Nerd For Tech
Published in

Nerd For Tech

Implementing the Jumping Animation

Todays challenge was getting the jump animation into the Player object. If you need a more detailed tutorial, read the previous sprite prep article. I’ll just share the steps in a nutshell: Just like the previous time, we select the player sprite, hit the drop down animation and select ‘Create New Clip’. then save it as Player_Jump in the appropriate directory, drag the frames into the timeline, and set the speed.

The new animation will appear in the Animator window:

Double click on the player jump and turn loop time off.

To set up the transitions, we’ll create a boolean parameter named isJumping.

When can we jump? We can definitely jump while standing still, and we can jump while running so we can make our connections between both but we’ll start with Player_Idle.

From Player_Idle to Player Jump, set the parameter isJumping to True. we’ll also turn off exit time and set the transition time to 0 because once again, we’re dealing with sprites and not skeletons that would benefit from interpolation. From Player_Jump to Player_Idle, we WILL have an exit time so just leave that checked.

Now for this to happen in our Player script, let’s call up our PlayerAnimation script and create a Jump() function with a bool parameter to pass in. Just to have a bit of fun and possible confusion, let’s call the parameter to pass in, isJumping.

Now we’ll be able to call them from our player script, in CheckMovement:

We’ll need to set the jumping to false when the player touches the ground, so the IsGrounded bool seems like a good spot:

You may have guessed there’s a problem here. This is a bool that is only being checked when the spacebar is being hit. We can fix that by creating a boolean holder that’s constantly being called:

Obviously this is just step one. Now we need to assign it, we’ll put it in our CheckMovement function to keep it out of Update.

And that should do it for the idle jump:

The idle jump is working flawlessly, attaching the running jump is a similar process:

From Run to Jump, turn off has exit time, 0 transition time, and conditions: isJumping = true.

Going back from Jumping to Run, leave Has Exit Time ticked, and use two conditions: isRunning is False, and speed > 0 to let Unity know it needs to go to the run animation instead of idle:

And the jump is now transitioning to its proper states!

Later we tweaked the jump animation to only use frames 6–15 excluding 7 and 11 and we stretched the last keyframe to around 2 seconds

I had to tweak the transitions that went back to the idle and run states a bit for it to work better: First has exit time had to be on, and I changed it to .5 and transition time to .05 seconds:

This resulted in a much smoother jumping experience:

That’s it for today! See you next time!



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