Moss Giant Setup Part 2

Simon Leen
3 min readSep 27, 2021

--

Objective: Setup AI for Moss Giant

As you can see above, the Moss Giant currently has an idle and walk animation with transitions applied but there is no motion. The idle state plays then transitions to walk and stays that way indefinetly as there is no movement logic or target set to trigger the back to idle state.

To get started we need to set up waypoints for the Moss Giants path and target. We can add these points using Transforms to the bass Enemy class as the other enemies will be moving too.

Next inside the Moss Giant script, we can start by creating a Vector3 for the target. This will be used to set which point is the current target and the Moss Giant needs to move towards. We will also need a handle to the Animator and the SpriteRenderer so we create variables for them and assign them in the Start method along with setting the Moss Giants speed and initial target. Settng the initial target becomes usefull if the Moss Giant initial position isn’t one of the two points.

For movement, we run a conditional if to check the Moss Giants position off the targets positon before setting the target to the opposite point. We also use the Animator handle to trigger the idle state at each target point before moving again.

The SpriteRenderer handle is used to flip the sprite on the X-axis depending on the direction the Moss Giant will travel to its current target.

To avoid movement or other actions such as flipping the sprite during the idle animation we run a conditional if to check if the current state of animation is the Idle and if so return without calling the Movement or Flip methods.

We now have a moving, animating Moss Giant that switches animation state to idle on each target before moving to the opposite point.

--

--

No responses yet