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.
Firstly the object must be a dynamic or kinematic to be able to be rotated,
in addition use SetAngularVelocity()
to achieve the rotation.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With