Player Animation 2.5D Edition Pt2

Now that we have our base animation for our player which is idling about it is time to get him into action and running across our level. So we need a run animation so lets go back to and get a run animation that we like for our player. Once we have the animation we like download it. Once downloaded drag the file into our fbx folder. Click on the animation > rig and select humanoid and click apply. Once applied duplicate the animation and drag it onto our player models folder. Once there drag it into your animations tab of your player.

Once completed create a transition from idle to running and running to idle. It should look like this.

Now when we transition it will run idle and then running on a loop, but we need to set this up when our speed is greater than zero to run. So let’s go to the parameters section and create a float speed parameter. Click on the arrow going from idle to the running and under the transitions tab a conditions section will appear and for the condition the speed must be greater than 0.1 to be trigger the run animation. Important to not have has exit time active. We also want to set our transition duration to 0.25.

Now do the opposite for running to idle and create another condition where instead of being greater than we want it to be less than. Keep having an exit time turned off for this one as well. Change the transition duration to zero for this one.

Now we are going to create an animation script to run all these animations through. So create a player animation script and place it in our scripts folder.

Open your player script and create a global variable for the Animator. Then within the start method we are going to get the component of the children animator. Now we have access to the animator controller and all of the properties in the animator. We need to change the getAxis to GetAxiRaw this allows us to access the maximum speed immediately. We want to make sure our speed is never going to go negative.

Next time we are going to focus on our player’s jumping animation.

Unity Developer