Adding a little freedom of movement.

Objective: Adding in alternative movements for the enemy.

Rose Owen
3 min readJun 24, 2021

Currently, the only movement the enemy has is spawning in a random location then slowly moving down while shooting at the player. By using the animation system in Unity, we can give the player some new movements.

First, we going to need an animator on the enemy, if you don’t already have one. To add one we can just click on the create button after clicking on the enemy.

Give it a name and save it in the animation folder to keep things tidy.

After all that, we can start to add in the movement for the enemy. By using the dopesheet and adding positions for the animation to loop between, we can give the enemy some new movement. As shown in the gif below.

Now when the enemy spawns, it will follow that path until it dies. Since we want to be able to add other movements in, we can add a trigger for the enemy animation to start playing. We can do this in the Animator.

Setting up an empty to be called as the default and then having the other animations get triggered from that will give the option to have many different movements.

Now we can set that trigger to start the animation, we can also remove the animation to still be able to call the normal movement. This can be done in a switch statement and by adding an ID system for each kind of movement.

2 Variables needed for this, 1 to store the animator and 1 for the ID.

We can add a random range for the ID to change between the different kinds of movements. Also, here we can check to see the animator isn’t null.

In the update method, we can use a switch statement to change between the new movement and the old one.

By going through all these steps again, we can add in many different kinds of animations/movements.

And with that, another feature is added and as always test things out to see they are working as intended. See you in the next one!

--

--