伙计们,
我正在尝试对球以一定角度撞击墙壁的碰撞实施某种行为。我希望球保持全速,但我希望反射角稍微柔和一些,以便它从来的方向反弹的更少。
我玩过摩擦、阻尼和恢复,但我的回弹角度似乎没有任何区别。
有谁知道我可以让 box2d 做我想做的事情吗?
球反射角
http://i.stack.imgur.com/lMwLN.png
谢谢您的帮助,!肯
伙计们,
我正在尝试对球以一定角度撞击墙壁的碰撞实施某种行为。我希望球保持全速,但我希望反射角稍微柔和一些,以便它从来的方向反弹的更少。
我玩过摩擦、阻尼和恢复,但我的回弹角度似乎没有任何区别。
有谁知道我可以让 box2d 做我想做的事情吗?
球反射角
http://i.stack.imgur.com/lMwLN.png
谢谢您的帮助,!肯
首先,你可以在你的世界中设置一个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;
...
}
我希望你能明白我的意思