Create a movement animation in Unity.

Improving the game feeling with animations

Rusben Guzman
2 min readSep 17, 2021

Objective: Create an animation for the horizontal movement of the spaceship

The first step is to create an animation controller and 2 animations one for the left movement and one for the right movement. Right click in the project window > create and select each element.

Then we have to open the animator tab and select the player animation controller. Within the controller we have to add the animations that we created. In this case I created an empty animation to use as an idle state and from that state I created 2 transitions to each animation, the left and right movement.

In the controller I created a variable called path. The idea is to use the value of this variable to make the transitions between animations when the value is 0 we stay in idle, when is greater than 0 we go to the left and when is greater than 0 we go to the right.

Now we add the animation controller to the player and open each animation in the animation tab. Once in that tab we only have to drop the sprites and configure the time.

In the player script I declared an Animator variable to get the reference to the player animator component. In the start function I used the GetComponent function to get the player animator. Then in the calculate movement function I created a condition to get the value of the horizontal axis and check the same condition than the logic in the animation transition with the path variable.

And that’s it!!! The player have a better movement

--

--

Rusben Guzman
Rusben Guzman

Written by Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

No responses yet