Let’s Cure Blindness (AI in Unity)

Valdarix Games
2 min readMay 16, 2021

How to let our AI “see” in Unity 2021

Well kinda….

When designing games we often need to create enemies that can see our player. Today we will talk about a quick and simple way to give sight to the enemy AI. In previous articles we developed a system that allowed our guards to patrol using a modular waypoint system.

A more sophisticated method would be to use a ray cast from our enemy and react if the ray cast hits the player. This method would be really helpful if our enemies needed to shoot at the player or needed a more precise set of eyes. However for our demo we only need the guards to be able to see the player to trigger a game over cutscene.

We want to do this in the simplest, least expensive way possible. So we are going to use the good old box collider for our guards eyes.

The box collider extends out to mark the end of the guards vision. It matches the length of the flash light cone.

The box collider method works well for this instance because we can setup the details of our box colliders size and allow the OnTriggerEnter() method be what detects when the player is seen by the guard.

Since my guard won’t actually be engaging in combat with the player I will use a box collider directly on the game object. However if we wanted to…

--

--

Valdarix Games
Valdarix Games

Written by Valdarix Games

Turning my passion for video games and software development experience into a focus on video game development.

No responses yet