Day 88 — Implementing Animations: Jumping Animation

Connor Fullarton
4 min readJun 11, 2021

Hey and welcome!

Before we get into the bulk of this I’ll show you something pretty helpful that you can do with animations if they’re not looking right. If you check out the below animation here you’ll notice that they’re not jumping in place and are instead jumping a few spaces forward:

Unfortunately for this animation it didn’t have a jump in place option for it, however all is not lost as we can actually edit that within Unity! If you click on any of the animation clips you made a copy of you’ll see these options in the inspector:

When I tested out the animation my character did jump in place however they didn’t really get any air and the animation was a bit off as well.

However, by checking the Bake Into Pose option for the Root Transform Position (Y) I was able to get the animation I was after.

If you come across any similar issues I recommend playing about with the Bake Into Pose options as you can at times drastically alter how your animation reacts and plays out in the game.

Setting up the Jump Animation

Now let’s get into the technical part of the jumping animation! Drag and drop your jumping animation into the controller and then have two transitions that lead from the jumping state and into the running and idle states. Then create one transition from running to jumping so that you have something like this:

With that done create a new bool parameter called Jumping. We’ll first put that to use in the transition from running to jumping by adding in the jumping is true condition.

The transition from the jumping state and the running state is a little different, there’s going to be two conditions. The first is when the speed is greater than 0.1 and jumping is false:

This is so that our player can smoothly transition back to running if they’re still in motion. With the transition between jumping to idle though the condition there only needs to be when jumping is false.

Lastly make sure that the Has Exit Time option has been unchecked for all of these transitions and you’ll be ready to add in the following code to make use of the new parameter:

private bool _jumping = false;void Update()
{
if (_controller.isGrounded == true)
{
if (_jumping == true)
{
_jumping = false;
_anim.SetBool("Jumping", _jumping);
}
if (Input.GetKeyDown(KeyCode.Space))
{
_jumping = true;
_anim.SetBool("Jumping", _jumping);
_velocity.y += _jumpHeight;
}
}
}

In the code here we’re creating our own instance of a _jumping bool and this is so that we can avoid the Jumping parameter in the animator being set to false on every frame that the player is grounded and not jumping. Everything else you should be able to tell what’s going on and it will give us this effect:

Now we just have one more thing to deal with before we move on and that’s to get the character to face to the left when they’re running or jumping that way!

--

--

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.