Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop the forces acting on a body in box2d

I am using box2d on the iphone to create a game. I have a body that is effected by gravity to move down and not right or left. It will get hit by another body and will then be moving right or left. I then have a reset button which moves the body back to its starting point. The only problem is that it is still moving right or left. How can I counteract the forces that a ball is already traveling? How can I get rid of this right and left movement when I reset my game?

like image 404
user891123 Avatar asked Sep 25 '11 05:09

user891123


1 Answers

Box2d automatically clears the forces each simulation step. I think you are just changing your body's position when resetting, but not its velocity. Add this code to your reset method:

body->SetLinearVelocity(b2Vec2(0,0));
body->SetAngularVelocity(0);
like image 57
Andrew Avatar answered Sep 22 '22 13:09

Andrew