April 28, 2012

How to move a body manually in Box2D? or Give a force to a body in Box2D, iPhone.

This is a sample code to move a body in Box2D .
First you have to make a body with variable name “moving_rec” and call the below function in a schedular at regular intervals.

-(void) moveBody{b2Vec2 force = b2Vec2(0,0);force = b2Vec2(0,3);//Giving the x an y to negative will move the body in opposite direction.moving_rec->SetLinearVelocity(force); //set Linear velocity for moving in a constant speed.}

Please leave your comments on this post.

Leave a Reply Cancel reply