How to let your AI See!
Objective: Extending our guards ability to detect movement within range
Let’s create a cube just in front of the security guard and scale it to the length of the area the guard may see.
Turn off the Mesh Renderer so you can only see the green outline of the collider and on the Collider Is Trigger is checked and rename this object to Eyes. Since the Eyes game object is a child of the Security Guard, where ever the guard moves, the eyes will follow.
Now let’s create the Eyes behaviour by creating a new script named Eyes and attaching it to the Eye game object.
Go ahead and open the Eyes script. The logic would go as follows, in OnTriggerEnter, check if the “other” tag is “Player” and if so then enable the Game Over Cutscene.
Play the game and as you will see, as soon as Darren is in the Security Guards detection area, it runs the Game Over Cutscene.
If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any further help.