Key frame Hierarchical Animation with Ragdoll

Jul 26, 2010 at 6:04 PM

I'm attempting to make use of this great physics engine in my game and have been learning the ins and outs.

I've implemented a ragdoll (torso, 2 arms, 2 legs, head), skinned it by rendering my sprites using the ragdoll bodies positions/rotations, and now I'm at the difficult part of creating a hierarchical keyframed animation system.  I have done key frame skeletal animations before. I've never connected it with a physics system however.

My biggest concerns are how nicely the two will play together.   My current plan is to do the skeletal update first then the physics update to nudge the parts around based on the impulses/gravity/other entities acting on it.  So, for each body in the ragdoll I'll get the keyframes for the animation's timestep and then calculate the final position via linear interpolation.  Then I'll set the body's position to that point.  After all the bodies are in the positions that the animation says they should be in I will update the physics simulation to allow it to do its magic.

I'm afraid it may cause fighting between the animation and simulation on where each body should be located and cause chaos.


What are your opinions or thoughts on the implementation and interaction with the physics system?

Jul 27, 2010 at 6:48 AM

Yeah, difficult stuff. You should decide first if the animation's word is final in the physics simulation, or whether it can be stopped by other objects. It would also try hard to not set position or rotation of the bodyparts directly, but instead use forces or at least linear / angular velocity.

Jul 28, 2010 at 1:07 AM
Edited Jul 28, 2010 at 1:08 AM
Ya that plan didn't work at all. I setup some keyframes and just jumped between them and it worked fine until I turned on the simulator at which point it fought against those movements trying to jerk them back into acceptable positions. I'm also getting legs flipping into the torso when the simulator tries to rotate them back to positions that the joints deem correct. I'm concerned about how accurate I can have my animations if I'm using velocities. I did a quick test and they seem okay, but they also shove the entire doll around a bit since I have a fixed angle joint holding the doll up. I'm not in the mindset (at least at the moment) to animate a sprite in terms of velocities. I'd think that would be super difficult to get what I want. I thought of another approach I'm going to try but it may not be as physics useful as I'd like. I am going to try to place the upper part of my doll in a box and the legs in a circle. I'll let the simulator update those to keep it from falling through the ground and running into things. They will be used to position the overall doll. I'll then disable the ragdoll's actual parts from being updated by the engine. Instead I'll position them through the normal skeletal animation updates. When the character dies I"ll then disable the box and circle and enable the doll parts. This should then give at least a falling physics based death animation that will reflect the environment that it died on. I'm guessing the switch from animated to ragdoll physics may be a bit jerky or snappy for that quick second but we'll see if I can get that far.
Jul 28, 2010 at 7:16 AM

Yes, it's done like that in many games.

Using velocity shouldn't be too hard if you know the current position/rotation of a bodypart and the target position/rotation. The velocity to set is just the difference. That works because you set it every frame.