2

我正在开发一个用户必须击中高速球的游戏。为了击球,我使用旋转关节连接了一个矩形体和演员,并启用了它的电机,以指定的速度(电机速度)旋转它。现在一切都很完美,但有时当球的速度很高时,它会绕过矩形体。使用碰撞侦听器,我发现正在发生碰撞,但球在碰撞后没有被反射。由于这种情况仅在球处于高速状态时才会发生,因此是否与碰撞的物体密度有关。还是负责它的旋转接头电机?我在这里错过了什么吗?

这是两个机构的代码

// 矩形体的方法

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;
}
4

2 回答 2

3

尝试isBullet=true在你的球体上使用属性

于 2013-05-09T09:24:06.360 回答
1

您是否尝试过使用这些属性:密度、摩擦力和恢复原状。

球可能移动得如此之快,以至于在撞击矩形体时,球的力量对于rec体来说太高了。这意味着球不能被记录体阻止,这就是为什么它会通过它。

只是一个猜测。

于 2013-05-09T09:16:21.340 回答