Creating A Modular Waypoint System For Your AI To Follow On Your Nav Mesh
Sometimes, when creating the movement for an AI, you may want to determine a set path for them to navigate. To do this, you will likely need to create a “Waypoint System” so that your AI knows its target destinations.
You’ll need to create a “List”, which will hold the transforms of all your AI’s waypoints.
Next, create a reference to your “Nav Mesh Agent” and call it in void Start.
Then you’ll need to create an “Integer Variable” to hold your AI’s current target from the list.
And you’ll also need a “Boolean Variable” to reverse your AI’s progression through the waypoints.
Don’t forget that you will need to add the namespace “using UnityEngine.AI;” if you are wanting to access Unity’s Nav Mesh components.
Now in Unity, you’ll need to create empty game objects for each waypoint within your hierarchy and adjust their transform position to your desired waypoint locations.
And lastly, drag and drop those waypoints onto your script in the inspector.