Framework: AI Movement

Suleiman Abdullah
3 min readMay 3, 2023

--

In the first step, I will establish a starting point and an endpoint.

In the second step, I will place the AI at the Start waypoint in the scene.

I will create 4 variables Transform, NavmeshAgent, int, and bool variables called wayPoints, agent, current waypoint, and isAgentReachedDestination.

When the game starts I want to move AI to the first waypoint.

Before moving AI to the next waypoint we are checking if AI has reached the destination then move to the next waypoint.

Then we need to check if the agent reaches the destination using a bool, then we need to check if we are at the end of the waypoint if so we set the bool to true and set the current waypoint to the last waypoint index to avoid an error.

This means if AI is not at the end means AI needs to move forward, but first we need to check if AI still moves toward the first waypoint, if so we set a bool value of “is agent Reach Destination” as equal to false. Then move AI to the next waypoint.

Last we are checking if the agent has reached the destination we stop AI.

Here is the final result.

--

--

Suleiman Abdullah

Self taught Unity Developer, who is passion about making games ,and he loves Math For Game Development