My journey becoming a Unity game developer: 2.5D Infinite Runner-Idle, Running, and Running Jump animations Pt.3

Objective: Setting up the player to be able to jump and double jump using their Jump and Running Jump animations.

Player jumping and double jumping in their respective animations.

First thing we want to do is access the Jumping and Running Jump animations. In the animations, we want to turn off Loop Time if it’s on as we will control the Player’s animation through code. With the Root Transform Rotation and Position, we will turn on the Bake into Pose to prevent the Mixamo animation’s Root Transform from controlling how each character will move in the game. This will also help with preventing a lot of inconsistent jumps as they will build upon each jump making the Player jump higher and higher. With Root Transform rotations we should use our Scene view overhead view in particular to see if the characters aren’t rotating on their own.

Player’s Jumping and Running Jump animations Baked into Pose.
Overhead view testing the Player’s movement to make sure it’s not rotating on its own.

Create 2 Bool Parameters name Jumping and Running Jump. These parameters will handle the transitions between the Idle->Jumping and Running->Running Jump animations.

Bool parameters created for Jumping and Running Jump animations in the Animator.

Create a Transition from Running to Running Jump. Turn off Has Exit Time as we want to go right away into the Running Jump animation. Under Conditions, create a new condition by clicking the “+” sign, selecting Running Jump and setting it to True.

Create a Transition from Running Jump to Running. Turn off Has Exit Time as well, and create a Condition of Running Jump equals False to go back into the Running animation if the User is still pressing the arrow keys moving along the Z-axis.

Transitions set for Running to Running Jump animations.

Create a Transition from Idle to Jumping. Turn off Has Exit Time, and create a Condition of Jumping equals True. Create a Transition from Jumping to Idle, Turn off Has Exit Time, and set its Condition of Jumping equals False.

Transitions set between Standing Idle and Jumping.

Now one thing we need to look at is how the animations play in the game when transitioning between each animation. If the animations look off, click on the transition between the 2 animations you may notice something doesn’t look right. Go to the Transition Graph, and maneuver the blend of the 2nd animation into the 1st animation. Use the Transition Duration to control the blend between the animations. Animations in the Transition Graph is a simple animation blend technique which needs it own special introduction.

Adjusting the animation’s transitions using the Transition Graph.

In the Player script, we want to create another variable name runningJump equals False to go with the jumping variable which is already set to False. Down in the Update() function under the IF condition checking if the Player’s controller is grounded, set runningJump variable to True.

Running Jump Bool type variable created and set to True when the Player is on the ground.

When the Spacebar is pressed for a regular jump and double jump, we will use the anim variable to access the Animator and use the SetBool parameter to set the Jumping animation to True for both jump and double jump.

Animator SetBool parameter used to activate the Jumping animation for a regular jump and double jump.

Outside of the Else() function checking for the double jump and wall jump, create another IF condition checking if the Spacebar is pressed AND runningJump is True. If it is, set the yVelocity to equal the jumpHeight, use the anim to SetBool the RunningJump animation to True, and set runningJump variable to False to prevent it from continuously jumping in the air.

When spacebar is pressed and Running Jump is True, Animator’s SetBool will play the Running Jump animation.

We have to check IF jumping is True AND runningJump is True. If they both are, we will set the jumping and runningJump variables to False. Also, set the anim variable’s SetBool for both Jumping and RunningJump animations to False.

We have to place this IF condition behind the horizontalInput rotation IF condition, and before we check to see IF the Player is jumping. If we place this condition elsewhere, the Jumping and RunningJump animations will not play, but instead we will see the Player moving and jumping in their Idle animation only.

After landing on the ground, if jumping and running jump is True, set them and their animations to False.

The Player is jumping and double jumping in their respective Jumping and RunningJump animations.

Jump, Double Jump, and Running Jump animation playing.

Next time we will begin working on a Ledge Grab System in which the Player will have the ability to jump up and grab, hang from, and pull themselves up off a ledge.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store