Adding Running Jump Animation
Now that we have our running animation down, it is time to work with the jumping animations, just like how we got our idle animations, we will be getting our animations from Mixamo.
Preparing the Jump Sequence:
After downloading and importing the animation files, and applying it to the Animator we need to create a new type of parameter which will gauge the the conditions.
For this parameter we will use an Boolean, this true or false statement will trigger when to jump and when not to, it will give us the most precise control over when it toggles via with our scripts.
When setting the conditions where the states Jump -> Running we will be adding multiple of conditions to make sure that the Animator doesn’t get confused. We do the same setup for the Jump -> Idle to prevent animation confusion.
Scripting the Animation:
Now it is time to toggle the animation via scripts, just like how to trigger the movement script, we will follow a similar setup for the jumping animation. The only difference is, since this is a Boolean parameter we need to add a handler at the top.
Then in the Update method, we are going to create an Boolean switch. Start by creating and IF statement which states whenever the Boolean “_jumping = true” then set the boolean to false, at the same time toggle the animation parameter to false as well. This If statement is what toggles off the Jumping Animation.
To turn on the animation, during the Input key down, we will set the Boolean of _jumping to equal to true, then reference the animator’s parameter Boolean to be set to true as well. Now every time we press the space bar, that boolean will be triggered. Then in the next frame since the Boolean is set to true, it will automatically be set to false. We have created an Boolean Switch.
Now back in Unity, you should be able to see that the jumping and landing and going back to either Running or Idle is very fluid and precise. Looking at the Animator while in Play Mode, you can see the animation transitions happen in real time.