Animating Turn Left & Right

Ryan McCoach
4 min readJun 25, 2021

--

In this article I will go over how to add a turning left and right animation when the player moves in that direction.

We already have the turning left and turning right animations imported into our project. In the animations I am use they are only two frames because we want the plane tilt to be quick, so the player feels the turn directly when they hit the corresponding button.

This is what the Player’s animator looks like with the default Player state being a four frame animation.

We will make a Transition from the default Player state to either the Turn Left or Turn Right animation.

A float Parameter (Turning) is needed to determine if the Player is moving left or right and we set it at 0.

Lets jump into the Player script and looking at the Calculate method that is called in the Update, so it is always being updated. In this method, we have a variable called horizontalInput that is returning a value between -1 to 1 using the Input.GetAxis (Horizontal) moving left or right. When not moving left or right the value is 0, when moving left this value increments to -1 and moving right the value increments to 1. This is important because we know if the player is moving left if that value is less than 0 and moving right if it is greater than 0.

Knowing this, we are going to get the animator and set the float parameter (turning) to the value of the horizontal input.

For the Turn Right transition we add the Turning condition and are checking to see if that horizontal input value is greater than 0. This means the Player is moving right, so we want to transition to the Turning Right Animation.

For the Turn Left transition we add the Turning condition and are checking to see if that horizontal input value is less than 0. This means the Player is moving left, so we want to transition to the Turning Left Animation.

Both of these transitions will not have an exit time because we want the animation to transition into the return animation right away. We want it to be responsive.

Next, we want an animation to transition from the Turning state back to the default state, so we are going to reverse each of the Turing animations.

It is extremely easy to reverse animation in Unity. We just need to set the Speed from 1 to -1.

Condition to Returning Right
Condition to Returning Left

For the transition to this reverse animation, we again are checking the Turning parameter value from that horizontal input. If the value is 0.1 that means the player is done finishing moving right because that value is now incrementing down from 1. If the value is less than -0.1, this means the player is done finishing moving left because that value is now incrementing up from -1.

Transition back to the default Player state, the transition setting will be the same for both. This transition will have an Exit Time. It will wait the amount of the Exit Time (1 second) before returning to the default Player animation. We also want to make Transition Duration and Transition Offset to 0 because we do not want any blending of animations to happen.

Adding these turning animations just gives the game more of a publish and makes the player feel more connected to the plane they are controlling.

--

--

No responses yet