Changing Body Direction

Topics: Developer Forum, Project Management Forum, User Forum
Sep 20, 2012 at 5:25 PM

I was curious if there is a way to code the ability to turn a character with multiple joints and bodies connected, so that it is facing the opposite direction. There is a character that has a head (circle body) that is at an angle as he walks to the right (as though he has a hunchback). When we have the character turning to the left, the sprite will change and appear as though he is going left, but the body remains the same at all times. Is there a way to code a mirrored image? Is there another way of accomplishing this?

Sep 20, 2012 at 7:09 PM

It could be easier to have three fixtures on the head body each representing a logical state. When he's going left enable collisions for the left fixture, when he's upright enable collisions for the upright and when he's going to the right enable collisions for the right - all using collision categories (CollidesWith()). Like a hydra. It's very fast and efficient except when there is interpenetration (touching a wall) but this should be checked in testing. I don't know what the joint situation is but in my implementations of similar situations I usually attach joints to a body that is common to the different states. Joints don't like much to be instantly and unphysically fiddled with. 

Also consider not changing the collision shapes at all. How a character is drawn, i.e. what it looks like, does not necessarily have to be what the character physically is. Some cheating and illusion can lead to much greater performance. Games cheat all the time.