我正在开发一种用户必须击中高速球的游戏。为了击球,我加入了一个长方体,演员使用旋转关节并启用其电机,以指定的速度(电机速度)旋转它。现在一切都很完美,但有时当球的速度很高时,它绕过了直肠体。使用碰撞列表器我发现碰撞正在发生,但碰撞后球没有反射。 因为只有当球高速行驶时才会发生这种情况,是否是碰撞的物体密度的bcoz。或者它的旋转关节电机是谁?我在这里错过了什么吗?
以下是两个机构的代码
//矩形体的方法
public Body createRectangleBodyPart(float x, float y, float width,
float height, short groupIndex) {
PolygonShape shape = new PolygonShape();
shape.setAsBox(width*WORLD_TO_BOX, height*WORLD_TO_BOX);
MassData massData = new MassData();
massData.mass = 15;
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.KinematicBody;
bodyDef.position.y = y*WORLD_TO_BOX;
bodyDef.position.x = x*WORLD_TO_BOX;
body = world.createBody(bodyDef);
body.setMassData(massData);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = 1;
fixtureDef.friction = 100f;
fixtureDef.restitution = 0.5f;
fixtureDef.filter.groupIndex=groupIndex;
body.createFixture(fixtureDef);
shape.dispose();
return body;
}
//球体方法
public Body createRoundBodyPart2(float x, float y, float radius,
short groupIndex, float density, int mass) {
CircleShape shape = new CircleShape();
shape.setPosition(new Vector2(0, 0));
shape.setRadius(radius*WORLD_TO_BOX ); // *18
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.y = y*WORLD_TO_BOX;
bodyDef.position.x = x*WORLD_TO_BOX;
MassData massData = new MassData();
massData.mass = 8;
Body body = world.createBody(bodyDef);
body.setMassData(massData);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = 0.5f;
fixtureDef.restitution=0.007f;
fixtureDef.filter.groupIndex = groupIndex;
body.createFixture(fixtureDef);
shape.dispose();
return body;
}
答案 0 :(得分:3)
尝试在球体上使用isBullet=true
属性
答案 1 :(得分:1)
您是否尝试过使用这些属性:密度,摩擦力和恢复原状。
球可以移动得如此之快,以至于在与矩形体撞击时,球的力量对于身体来说是高的。这意味着球体不能被球体阻挡,这就是它通过它的原因。
只是一个猜测。