Quantcast
Channel: CoderzHeaven » Cocos2D
Viewing all articles
Browse latest Browse all 10

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

$
0
0

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.


Viewing all articles
Browse latest Browse all 10

Trending Articles