AI Movement

Jack Leavey
2 min readAug 24, 2022

--

This placeholder block contains the movement logic for the AI.

With the traversable path now established for the AI, it’s time to assign them some basic movement function.

Before assigning the enemies their specific path, I set up an end goal for the AI to move towards. This is simply an invisible square that will be able to detect collisions and hold a transform for the AI to navigate towards.

This is the finish line for the AI enemies.

Next, I made a total of 9 “waypoints” that were all behind pillars, out of sight of the player. These are safe zones the AI will select during their transit to use as cover from the player’s attacks.

These white capsules are the waypoints. These are not visible from the player’s locked location, making them safe from potential attacks.

With these things established, I set up the first version of the AI: Move to the end goal.

In code, its as simple as instructing the NavMeshAgent to navigate to a new transform.position.

_agent is the handle to the NavMeshAgent on this object. _endGoal is a variable holding the invisible cube that serves as the finish line.

Next time I will cover the AI states; Run, Hide, and Die. The AI will select which waypoint it thinks is can safely reach, then hide there for a random amount of time before continuing forward. The die state will handle on enemy death logic.

--

--

Jack Leavey
Jack Leavey

Written by Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!

No responses yet