GameDevHQ Crash Course #23 AI and enemy pathing

Jason Dixon
3 min readApr 1, 2021

--

Stealth Game & Cinematography-Enemy AI

Now that we have the ability move through the scene lets add some enemies to avoid. 3 Guards in the first half of the scene and some cameras in the second half that you have to avoid. So we set up some guards. Then we make some empty game objects for them to move towards. After that we make ourselves an empty serializeable list of waypoints we can make each guard unique without having to make seperate scripts for each.

Then for our code making sure we have a null check for waypoints and our animator we can then move our guards towards their respective points, once we reach the last waypoint and as long it is not the only waypoint we reverse the waypoints and get them on their way after a brief delay, this gives us our pathing for the guards, but at this stage they are ‘blind’ in a sense, we need a way for them to sense the player and to trigger our game over cutscene.

So lets add to each guard a 3D cube that we have removed the mesh on and placed it in front of our guards in a size that we would like them to detect, I make these just shy of the length of their flashlight distance.

After that we add a script to that invisible box that when the player enters the field it triggers the game over cutscene. We add a similar trigger to the cameras in the back.

We also change the cone colour to red on discovering the player and give a short delay before starting the cutscene this time.

--

--

No responses yet