Nerd For Tech
Published in

Nerd For Tech

Mobile Games In Unity: Jump Animation Logic

In previous articles I’ve demonstrated how to create animations using 2D sprites, and how to set up transitions from Idle to Running in the Animator window. This article will demonstrate the logic behind the jump animation.

I’ve created the animation and imported it into the animator window. I want to be abe to jump when Im running and when I’m in idle. SO I’ve set up transitions from each one to the jump animation.

In order to transition from these to jumping I need a parameter. I’ve set up a bool called “Jump”.

The reason I used a bool is so that I could control when the animation ends. I want the animation to continue while I’m not grounded. As soon as I’m grounded I want to go back to either running or idle depending on my movement float value.

In my PlayerAnimations class I have a new public method that controls the bool parameter by feeding a bool called “jumping” into it.

Then I set the value “jumping” to whatever it is in the Player script.

When I jump, the bool is true and when I land the bool is false. This will flip the animation on and off. I also set up another condition in the animator for when I transition back to running. If “Move” is greater than 0 and “Jump” is false I’ll transition back to running. Otherwise I’ll transition back to idle. Thats all there is to it!

I personally think the default jump animation is too long. So I removed some of the frames and made the jump look a little better in my opinion. Play around with it and set it how you like! Thats what this is all about anyway!

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

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