Agent Death
General AI Behaviours
- Go to the where the player is
- Attacking the Player
- Stopping Actions Upon Death
- 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:
“SetDestination” can only be called on an active agent that has been placed on a NavMesh.
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.
That’s it! You now have a complete Zombie Brain which can be used for multiple types of agents!
You can extend from this tutorial and add some more complex logic to your agent!