How to let your AI See!

Using Triggers and Game Events

James Lafritz
2 min readJun 1, 2021

There are several ways to give sight to my characters. I can do a raycast from it’s eye position or I can use a trigger collider to represent it’s eyes. I am going to go with the quick and simple way. I am using my ScriptableObject Game Event system to play the cutscene.

Setting Up the Eyes

I added a 3D cube to the Guard.

I then Positioned the cube to a spot that I wanted.

I want his sight to be where the flashlight ends while he is walking. I think a Position of 2 on the Z axis and a Scale of 3.5 on the Z axis works really well for me.

I then added a Game Event Trigger to the Eyes.

I then Assign the Game Over Event to the Trigger.

I add the Unity Game Event Listener Component to my Game Manager in the Scene. I assign the Game Over Event as the Event I want to Listen to. In the Unity Response I Activate the Game Over Cut scene and Deactivate the Guards.

Now when the Guard sees the Player the Game is Over.

--

--

James Lafritz

Excited about changing my hobby into a new carer with GameDevHQ course.