Box2D body rotation with setTransform
Posted
by
thobens
on Game Development
See other posts from Game Development
or by thobens
Published on 2014-08-21T18:57:42Z
Indexed on
2014/08/21
22:28 UTC
Read the original article
Hit count: 639
I' having a problem rotating a body with setTransform()
, The body has multiple sensors that should rotate with the player. The rotation works but it rotates around the bodys local 0,0 position instead of the center. Note that the game is in a top-down perspective and the player can go in four different directions, thus I need to rotate him immediately (in one tick) in 90 degrees steps.
Up:
Down:
I can't find a way to set the rotation center.
Here's the code I use to rotate it:
float angle = direction * 90 * MathUtils.degRad; // direction is an int value from 0 to 3
body.setTransform(body.getPosition(), angle);
I also tried body.getLocalCenter().set()
and bc.body.getMassData().center.set()
but it didn't seem to have any effect. How can I rotate the body around its center?
© Game Development or respective owner