Páginas

Unity3d: kill a character and make him die like a ragdoll

The other day, I shown a friend of Rosario Game Dev the lastest version of my game where I introduced bombs and explosion. He told me it would be great that when a bomb explodes, characters fly over the scene and that I could achive that by using a ragdoll. You can see a proof of concept here http://bit.ly/17pl47F

So, what's a ragdoll? A ragdoll "is a children's toy. It is a cloth figure, a doll traditionally home-made from (and stuffed with) spare scraps of material" and the same approach is used in video games.

Unity has a simple wizard that lets you quickly create your own ragdoll. You simply have to drag the different limbs on the respective properties in the wizard. Then select create and Unity will automatically generate all Colliders, Rigidbodies and Joints that make up the Ragdoll for you. (something you need to know / guess, as a ragdoll is basically a collection of rigibodies it will be affected by physics, gravity and forces)

Here you have a Unity 3D Ragdoll Easy Tutorial (this all you need to know to make a ragdoll)


This is really easy, but what if the character have any other logic or components like animators, rigidbody, script, etc?

Let's take a look at Ethan from Unity3d Project #01: Stealth. Ethan has a lot of components attached to him.


If I just add the ragdoll to Ethan, It'll be a completly mess (I've already did it, try it by yourself), so what can we do? These are the step I follow (guided by some answers I found on the Internet):
  1. Create a ragdoll to Ethan
  2. Disable all child (ragdoll) rigidbodies (script AnimatorToRagdoll.cs)
  3. When Ethan dies, destroy / disable main components (With a mouse click, Ethan dies)
  4. Eneable all child (ragdoll) rigidbodies 

The result is here http://bit.ly/17pl47F  With a mouse click, Ethan dies

You can download the full project here: http://bit.ly/1dYsO1I