How to make Box2D bodies automatically return to a initial rotation
Posted
by
sm4
on Game Development
See other posts from Game Development
or by sm4
Published on 2013-10-03T16:39:07Z
Indexed on
2013/10/17
16:28 UTC
Read the original article
Hit count: 301
I have two long Box2D bodies, that can collide while moving one of them around with MouseJoint. I want them to try to hold their position and rotation.
- Blue body is moved using MouseJoint (yellow) towards the Red body. Red body has another MouseJoint - Blue can push Red, but Red will try to return to the start point thanks to the MouseJoint - this works just fine.
- Both bodies correctly rotate along the middle. This is still as I want. I change the MouseJoint to move the Blue away.
- What I need is both bodies return to their initial rotation (green arrows)
- Desired positions and rotations
Is there anything in Box2D that could do this automatically? The MouseJoint does that nicely for position. I need it in AndEngine (Java, Android) port, but any Box2D solution is fine.
EDIT: By automatically I mean having something I can add to the object "Paddle" without the need to change game loop. I want to encapsulate this functionality to the object itself. I already have an object Paddle that has its own UpdateHandler which is being called from the game loop. What would be much nicer is to attach some kind of "spring" joint to both left and right sides of the paddle that would automatically level the paddle. I will be exploring this option soon.
© Game Development or respective owner