Implementing range detection
Our work in Chapter 6, Talking Heads, left us with an enemy that becomes aware of the player on a button click. Let's begin where we left off and improve this to make a smarter enemy that automatically attacks the player when he comes within a certain range.
Looking at the scene
We will start by opening our scene:
In the Unity project, open
Chapter9_Start
by navigating to File | Open Scene… | Chapter9_Start.The scene consists of the main office geometry and a single female zombie character. The
FPSController
prefab will allow us to navigate the scene.Press the Play button in the top center of the Unity interface.
The female zombie is currently set up to idle in place. We can approach and nothing happens at this point:
In the next step, we will add the zombie's AI script and allow her to detect the player.
Adding the initial AI script
We are starting with the zombie's script that we completed in Chapter 6, Talking Heads. The enemy is able to target the player, but we...