Setting conditions

We will need to provide our enemy tank with a few conditions to transitions states. These are the actual parameters that will drive the functionality.

Let's begin with the Patrol state. In order for our enemy tank to go from Patrol to Shoot, we need to be in range of the player; in other words, we'll be checking the distance between the enemy and the player, which is best represented by a float value. So, in your Parameters panel, add a float and name it distanceFromPlayer. We can also use this parameter to determine whether or not to go into the Chase state.

The Shoot state and the Chase state will share a common condition, which is whether or not the player is visible. We'll determine this via a simple raycast, which ...

Get Unity 2017 Game AI Programming - Third 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.