Reducing the angle of reflection using Box2D
Folks,
I'm trying to implement a certain behavior to a collision where a ball hits a wall at an angle. I want the ball to maintain full velocity, but I would like for the angle of reflection to be somewhat muted, so that it bounces back less from the direction it came.
I've played around with friction, damping, and restitution, but nothing seems to make a difference in my return bounce angle.
Does anyone know of a way I can get box2d to do what I'm wanting it to do?
Ball angle of reflection
开发者_如何转开发 http://i.stack.imgur.com/lMwLN.pngThanks for the help,! ken
Firstly,you can set a contactListener in your world, and then ,find out the exactly collision between the ball and the wall. Secondly,find out the collision point. Last, calculate the angle between collision point and body center.
such as
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;
...
}
I hope you can understand what I mean
精彩评论