Let your AI see in Unity

Daniel Kirwan
2 min readJun 24, 2021

--

Objective: Create a simple way for my guards to detect the player and trigger the game over cutscene

There are a couple of ways that you could set up some eyes for your AI, I have made a simple set up that is basically a box collider attached to the guards head. You could also use raycasting to do the same as I have.

I first created a cube as a child object to the guard and then disabled the mesh renderer for the cube. Now I set up the box collider as a trigger so that objects can pass through it and not use Unity’s physics system. For the trigger to work, one object involved in the collision needs to have a rigidbody. I added this to the eyes object I have created and disabled gravity.

This script for the eyes is a simple script that has a variable for a gameobject that will be my game over cutscene object and an ontrigger enter method.

The method has a simple check to make sure that the eyes are colliding with the player and then setting the gameover object to active. This is instantly run the cutscene that I have previously made. The cutscene could use some adjustments but that’s for a later date.

--

--

Daniel Kirwan
Daniel Kirwan

No responses yet