Flip a character

General discussion about Box2D tutorials
Post Reply
Oscar
Posts: 14
Joined: Sun Dec 23, 2012 3:56 pm

Flip a character

Post by Oscar »

Hey,

I've created a rag doll character in rube that I've been able to do skeletal animation on, using mouse joints and xml data coordinates. Body parts have limited rotation by revolute joints etc. But I've run into trouble. I can't figure out how to make this guy flip and walk in the opposite direction, which obviously is really important. Every part of him needs to mirror somehow, joints needs to receive new limits etc.

I'd love to see some sort of tutorial on this or if anyone can point me in the right way of thinking please share! The only hints google offered was this thread http://gamedev.stackexchange.com/questi ... n-in-box2d - which basically suggests to keep a mirrored version and switch between the two versions. I'd see that only as a last resort since it would break the simulation, be heavier on the computer and create jitter the moment you switch direction.

I've attached a screen shot from rube to get a feel for how I set up the character.
Thanks
Attachments
Rube screenshot
Rube screenshot
rube_character.jpg (184.58 KiB) Viewed 14019 times
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Flip a character

Post by iforce2d »

Unfortunately those stack exchange answers are correct. Box2D offers no method for dynamically changing shapes on fixtures, let alone an entire structure of bodies with joints. Since there is no third dimension to gradually rotate the bodies through, what you are talking about is essentially a teleport, and will require some careful management to keep it looking reasonable.

As mentioned in the question you linked to, you can create two sets of SetActive(false) on one set of bodies so that it is ignored from the simulation. I don't see how this would break anything or be heavier on the computer.

Jitter when you switch direction though, will indeed be a problem, as will other potential cases such as when the guy turns around his foot might be sticking into a wall etc. I think this is up to your game to manage somehow, and there is not really an official solution... I guess you would want to keep the overall center of mass in the same place. I don't think it will be that easy, which is probably why we don't see many games like this around :)

One thing I might suggest though... your character looks fairly symmetrical, but not perfectly symmetrical. Perhaps you could make him perfectly symmetrical, so that when he changes direction you can just reposition the existing bodies and change the joint limits, that way you don't need to switch between two sets of bodies.
Oscar
Posts: 14
Joined: Sun Dec 23, 2012 3:56 pm

Re: Flip a character

Post by Oscar »

Thanks, for the info! Bummer there's no better way. But maybe a mirrored version isn't that bad after all. I was thinking it would be heavier since you'd have to setup those bodies etc, but then again they won't be in the simulation until needed. I guess the jitter could be minimized with some decent animation, trying to cover it up :)
metalbass_92
Posts: 18
Joined: Wed Dec 26, 2012 12:27 pm

Re: Flip a character

Post by metalbass_92 »

You could activate the flipped version with invisible sprites when the animation starts and set them to visible when this ends. The jittering won't disappear, but with that extra frames it shouldn't be much noticeable.
Xavier Arias
Cocos2d-x Game Programmer
Oscar
Posts: 14
Joined: Sun Dec 23, 2012 3:56 pm

Re: Flip a character

Post by Oscar »

Yes, it will definitely need some sort of transition to cover up the switch
Post Reply