Box2d联系人监听器碰撞

时间:2017-05-11 09:56:47

标签: java libgdx box2d

我正在尝试使用Box2d实现单向平台。这是我的代码:

public void preSolve(Contact contact, Manifold oldManifold) {
    Fixture platform = null;
    Fixture ranger = null;

    Fixture fa = contact.getFixtureA();
    Fixture fb = contact.getFixtureB();

    if (BodyUtils.isPlatform(fa.getBody()) && BodyUtils.isRanger(fb.getBody())) {
        platform = fa;
        ranger = fb;
    } else if (BodyUtils.isPlatform(fb.getBody()) && BodyUtils.isRanger(fa.getBody())) {
        platform = fb;
        ranger = fa;
    }

    if (platform == null) return;
    Body platformBody = platform.getBody();
    Body rangerBody = ranger.getBody();

    int rangerTopY = (int) (rangerBody.getPosition().y + ((RangerUserData)rangerBody.getUserData()).getHeight() - 0.5f);
    int platformBottomY = (int) platformBody.getPosition().y;
    if (rangerTopY == platformBottomY) {
        contact.setEnabled(false);
    }
}

问题是contact.setEnabled(false)已调用但无效。为什么会这样?

0 个答案:

没有答案