Agent Death

General AI Behaviours

  1. Go to the where the player is
  2. Attacking the Player
  3. Stopping Actions Upon Death
  4. Stopping the Agent on Death

3. Stopping the Agent on Death

As you’re play testing and shooting the agents, you may notice that when an agent dies, an error occurs inside the console:

Since there is no context of an agent dying, the highest priority context is Attack Player. First, create another Observer, IsAgentAlive.cs. This Observer is like the IsPlayerAlive Observer.

using UnityEngine;
using InitialPrefabs.DaniAI;

public class IsAgentAlive : BoolObserver {

    private EnemyHealth enemyHealth;

    public override void OnStart () {
        enemyHealth = GetComponent<EnemyHealth> ();
    }

    public override bool OnObserverUpdate () {
        return enemyHealth.currentHealth > 0f;
    }
}

An agent is considered dead when the health’s value <= 0. Add the IsAgentAlive Observer and a new Decision, Die, to the Editor. The Die Decision has the highest priority out of all of the Decisions with a Priority of 3.

adding-death

That’s it! You now have a complete Zombie Brain which can be used for multiple types of agents!

agent-death

You can extend from this tutorial and add some more complex logic to your agent!