Character Contoller with Ragdoll

Could someone point me in the right direction of a tutorial showing me the right way to do this?

I have a character walking left to right across the screen, he is controlled by a character controller and I have all his animation setup correctly. I now want him to ragdoll to the ground when he dies, on collision with certain objects in the world.

I’ve used the ragdoll wizard, and at first I had a problem where the character was glitching about up and down the y axis. I guessed this was because the ragdoll was colliding with the character controller, so I went through disabling all of the colliders created by the ragdoll wizard, and enabling them again in code once the Character Controller detected a collision. This works but is still quite glitchy when the character ragdolls and also the ragdoll seems to lose all momentum the character had before the collision. I tried using Physics.IgnoreCollision(charController.collider, hit.collider); when it collides but this doesn’t help.

Am I going totally the wrong way about this??

Any tips greatly appreciated :slight_smile:

UPDATE

Still struggling with this, am I supposed to apply a force to the ragdoll similar to the walk speed? If so how would I go about this?

Thanks!

Typically, what you do is enable ragdoll when a certain action occurs (like death, or hitting the ground). Otherwise, you’d use standard animation.

Even in a game with as complex of animations as Assassin’s Creed, the ingame character isn’t a ragdoll. Rather, the animation team creates thousands of small animations, which are blended to create dynamic looking movement.

Often, there’s some code combined with animation. For example, in Grand Theft Auto (IV and V), if you stand with one leg on a kerb and the other on the street, you’ll see the leg bend dynamically. This is done with inverse kinematics, which is done with a combination of code to check for ground beneath the character’s feet, and an animation rig, which is a set of “bones” and their relations to each other.

In the same example, however, when your character moves their torso around, pops their neck, or lights up a cigarette, those are pre-made animations, and there is nothing dynamic about them. They are triggered when the character is registered as idle, and they occur randomly.

To control this kind of setup, you’ll need to determine which animation to run based on the state of the character. Running and walking, idle, jumping, and so on, each typically have a pre-baked animation. This question addresses how to blend animations in Unity Animation blending. - Unity Answers

However, to do dynamic animation, like checking for height to the floor, you may have to do this manually (unless there are utilities that I’m not aware of). Doing this manually will consist of writing a much more in-depth set of state-checking functions. For example, with the legs-on-stairs idle scenario, you could create null gameobjects at the limit of the character’s legs, and corresponding ones at their hips. Then, do a raycast from hips to feet, and draw the foot wherever the raycast hits, unless it goes beyond the limit. If using a rigged model, you may be able to get the knee and leg to look normal. Note, however, that inverse kinematics (IK) rigs have a tendency to do “wonky” things. You might find it easier to animate a leg-up position, and blend it with a leg-down position. Not having tried it in Unity (only UDK, and that was some time ago), I couldn’t tell you which to do.

For 2d in unity, however, there exists a set of tools that will allow you to animate in-editor and do blending there. You could therefore probably do a lot more dynamic things. I haven’t used it, so I can’t attest to it’s usability.

tl;dr : don’t use ragdolls except for when your character goes limp. Use other methods for when the player has control, or when a pre-determined action is taking place.

Also, I believe ragdolls on death are illegal in Germany, due to anti-violence/gore legislation. They may also be illegal in Australia. Probably not something to worry about, though.