Added a little death animation before the ragdoll

Death Animation

Rather than create a new ragdoll prefab of the Unit I turned the Unit itself into a ragdoll and made a death event StateMachineBehaviour that runs after the animation stops which destroys the animator causing the ragdoll physics to take over.

I also had to make sure to destroy all the components on death to ensure no future memory leaks.

5 Likes

That looks really nice! Good job!

2 Likes

So to update making the Unit model a ragdoll caused an issue where the BulletProjectile was not spawning at the Shoot Point so I had to go back and do it your way. :sweat_smile:

I’ve been meaning to say this from your first post, but I don’t want to sound like I’m saying ‘my idea is better than yours’: You could leave the ragdoll as is. Just play your death animation first, before switching to the ragdoll. It’s what you had, but instead of switching this character to ragdoll physics, you do the existing bits where we switch to the ragdoll prefab

1 Like

Yeah that’s what I ended up doing. Tried out my way and found there where some problems.

1 Like

There is a way to make a Hybrid Unit/Ragdoll that won’t interfere with those annoying bullet physics:

  1. Find each RigidBody on the character that is a Ragdoll joint and change the GameObject’s Tag to “Ragdoll”
  2. Add this Ragdoll Minder script:
public class Ragdoll
    private Collider[] allColliders;
    private Rigidbody[] allRigidbodies;

    private void Start()
    {
        allColliders = GetComponentsInChildren<Collider>(true);
        allRigidbodies = GetComponentsInChildren<Rigidbody>(true);

        ToggleRagdoll(false);
    }

    public void ToggleRagdoll(bool isRagdoll)
    {
        foreach (Collider collider in allColliders)
        {
            if (collider.gameObject.CompareTag("Ragdoll"))
            {
                collider.enabled = isRagdoll;
            }
        }

        foreach (Rigidbody rigidbody in allRigidbodies)
        {
            if (rigidbody.gameObject.CompareTag("Ragdoll"))
            {
                rigidbody.isKinematic = !isRagdoll;
                rigidbody.useGravity = isRagdoll;
            }
        }
    }

When you want to set the character to Ragdoll (when it dies), call

GetComponent<Ragdoll>().ToggleRagdoll(true);
3 Likes

Neat, thanks!

Privacy & Terms