Setting up AI for our Moss Giant!

addam davis
3 min readNov 29, 2021

Objective: Create a waypoint system for the moss giant to walk between.

Since we have set up our enemies using abstract classes and inheritances we can continue to build our moss Giant. In this tutorial we are going to focus on setting up movement with waypoints.

We want the Moss Giant to switch between waypoints. We are going to create two waypoints for them to walk between. Instead of creating waypoints for every single enemy we can make it a property within the enemy class so we can make use of individual waypoints for each object.

Now we can go into unity and create these points. The easiest way to create waypoints is to duplicate the Moss Giant for visual representation. Drag the copy to where you want the waypoint to be.

I rename this to be Point_B_MossGiant.

Copy the original Moss Giant again and this will be your point A.

Remove all the components on both point A and B and delete their sprite child objects. On the Moss Giant drag the point A onto the point A slot on the inspector and point B onto point B.

From here we can open the Moss Giant’s script and begin working out the movement function. We need to check what their current target is.

If the Moss Giant’s position is the same as point A we want to change the current target to B, and If their position is equal to point B then change the current target to A. In the movement method we want to use a Vector3 Move Towards function. This take the Moss Giants position, the target position, The Moss Giants’ speed times time.deltatime.

From here we have created movement for our Moss Giant. In the next tutorial we are going to trigger the idle animation, and turn the Moss Giant around when they are walking to the left. Don’t be afraid to experiment with your animations and I’ll see you in the next tutorial!