Box2D body rotation with setTransform
- by thobens
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?