Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Box2D rotate an object, how?

How I can rotate an object in Box2D? Tried..

private static final double DEGREES_TO_RADIANS = (double)(Math.PI/180);
float angle = (float) (45*DEGREES_TO_RADIANS);
object.body.setTransform(object.body.getPosition(), angle);

..but not working.

like image 826
lacas Avatar asked Oct 31 '10 14:10

lacas


Video Answer


2 Answers

Firstly the object must be a dynamic or kinematic to be able to be rotated, in addition use SetAngularVelocity() to achieve the rotation.

like image 91
cocos2dcocos Avatar answered Sep 29 '22 22:09

cocos2dcocos


If you want to rotate the object to an angle then you use setTransform method like

b2body->SetTransform( playerBody_->GetPosition(), angleInRadian );

And if you want to rotate the body continuously then use SetAngularVelocity method like

b2body->SetAngularVelocity(<float32>)

Remember b2body object must be a dynamic or kinematic to be able to be rotated.

like image 43
Ali Raza Avatar answered Sep 30 '22 00:09

Ali Raza