Nerd For Tech
Published in

Nerd For Tech

Animating the Character part 2

Now that we have implemented an idle and a running animation in our previous article, let’s take a look at how we can add in a jumping animation along with flipping our character around so that he faces the direction he is running towards rather than just awkwardly running or jumping backwards. To start however, let’s see how we can go about adding in a running jump animation for our character. As for the animation we want, we can go back over to Mixamo and select one that we like.
From there, we repeat the process of the previous animations, however in this case we will want to make an additional adjustment to the animation because it naturally propels our character forward and we want to prevent that from happening:

Baking our rotation and position into pose will prevent our character from moving an additional amount. Otherwise, our jumps would look like:

In this case, I will be adding an animation for both a running jump and an idle jump. Once we have them added into our Unity HUB, we can add them to our animation window and create the transitions needed:

On top of the new parameter being put in place for our animations, we also need to create the conditions for the transitions. As we have an animation for both idle and running, our transition back to them will need to have the proper requirements to get back to those conditions. In order to do so, we will simply use the speed parameter along with the jump one to determine whether we are running after our jump or going back to being idle. With our jumps all set up, we can now look into how we want to set up our code. There is an option to run it as a trigger, however as we are continuously activating the animation, there could be small visual bugs that can occur. If this was a 1 and done animation, like a death, a trigger would be a better method to work with. So, we are going to use a bool for this case so that we can trigger it on and off more efficiently within our code. Once we create a bool in our script to work with, we can start to link the animation parameters and create our animation transitions:

As we can see, we will want to create a new if statement to end our animation when our player is grounded, and activate the animation when we press Space. To have the parameter set to true or false, we will link the status of our _jumping bool to the true or false statement of our parameter. With all of this in place, we can check within our game to see how it looks:

Now that we have our jumping in place, let’s take a look at how we can have our character flip around when we run in the other direction. To do this, we will want to play with our Euler angles and have our character flip when conditions are met:

With this code, we are having our character rotate based on the direction we are going. As long as the value of the input is positive, we will move towards the right, and we will move to the left if it is a negative input:

Now that we have a character model and animations for it in place, let’s start figuring out how we can get a ledge grab system in place so our character can reach that ledge that is just too far for the jump to clear.

--

--

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