使用Box2D减少反射角度

时间:2011-08-03 00:20:50

标签: box2d box2d-iphone

民间,

我正试图在碰撞中实现某种行为,其中球以一定角度撞击墙壁。我希望球保持全速,但我希望反射角稍微静音,以便它从它的方向反弹回来。

我玩过摩擦,阻尼和恢复原状,但似乎没有什么能比得上我的回弹角度。

有没有人知道我可以通过box2d做我想做的事情?

球反射角

image http://i.stack.imgur.com/lMwLN.png

感谢您的帮助,! 肯

1 个答案:

答案 0 :(得分:2)

首先,你可以在你的世界中设置一个contactListener,然后找出球和墙之间的确切碰撞。 其次,找出碰撞点。 最后,计算碰撞点和身体中心之间的角度。

,例如

void contactListener::BeginContact(b2Contact *contact)
{
    //find out the collision between the ball and the wall.
    ....

    //find out the collision point
    b2WorldManifold worldManifold;
    contact->GetWorldManifold(&worldManifold);
    b2Vec2 collisionPoint = worldManifold.points[0];

    //calculate the angle between collision point and body center.
    b2Vec2 bodyCenter = body->GetWorldCenter;
    ...
}

我希望你能明白我的意思