Lets Add a Zombie - dead Zombie on the ground can be pushed

In the lecture Zombie Runner - Let’s add a Zombie - after the Zombie is dead and laying on the ground, when I’m walking over him, I push him with my movement. How can I made the Zombie stick to the ground and just walking over him withot pushing him with my movement? Thank you.

Hi,

Does the zombie have got a collider attached? If so, disable both the collider and the rigidbody on the zombie when it dies. This way, you’ll disable the physics simulation for the zombie. Just leave the animator and the mesh renderer active, so your zombie won’t become invisible.


See also:

Hi Nina, Zombie has Capsule Collider and Rigidbody. I assume that this 2 properties should be dissabled in code in EnemyHealth.cs script. Ricks code is this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyHealth : MonoBehaviour
{
[SerializeField] float hitPoints = 100f;

bool isDead = false;

public bool IsDead()
{
    return isDead;
}

public void TakeDamage(float damage)
{
    BroadcastMessage("OnDamageTaken");
    hitPoints -= damage;
    if (hitPoints <= 0) 
    {
        Die();        
    }
}

private void Die()
{
    if (isDead) return;
    isDead = true;
    GetComponent<Animator>().SetTrigger("die");
}

}

Where in this code (or in another script) and what code should disable Rigidbody and Capsule Collider? Sorry I’m an old newbie. Thank you.

Regards, Tomaz

Hi Tomaz,

You are right. The two components should get disabled. The first step is to get a reference to those objects. We did that with the particle systems in “Project Boost” and in “Argon Assault”.

The second step is to disable the components. I currently do not know if we already used the enabled property of a component but there is an example in the API, which you could try to apply in your own project.

I hope this helped. Good luck! :slight_smile:

Hi Nina, I tried your method and I didn’t figure it out, but I have found a solution. In the same script EnemyHealth.cs I have added a line into TakeDamage method:

public void TakeDamage(float damage)
{
BroadcastMessage(“OnDamageTaken”);
hitPoints -= damage;
if (hitPoints <= 0)
{
Die();
GetComponent().isKinematic = true;
}
}

I have added → GetComponent().isKinematic = true;
and it did the trick. I can not push the body on the floor anymore. I’m so happy. Thanks Nina.

Good job!

I was not sure if isKinematic would have made the zombie an obstacle. That’s why I suggested to disable the Collider and Rigidbody completely. I’m glad you found a much simpler solution. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms