The Chase state

The Chase state is the second of the three in the enemy FSM. This state connects to both the Patrol and Attack states directly. It can be reached in one of two ways. If a patrolling NPC establishes a direct line of sight to the player, then the NPC changes from patrolling to chasing. Conversely, if an attacking NPC falls outside the reach of the player (perhaps because he is running away), the NPC resorts to chasing again. From the chasing state itself, it's possible to move either to the Patrol or Attack state, with the inverse conditions as those, which lead to chase.

That is, if the NPC loses sight of the player, it returns to patrolling and, if the NPC reaches within attacking distance of the player, it switches to attacking. ...

Get Unity 2018 By Example - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.