Animated Character Jump (Unity Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys today we're going to look at how we can add an animated jump to a character we'll look at how we can trigger animations when the character jumps falls and lands okay so we're going to start with this scene that has a character that can run around the character can jump but at the moment it isn't animated we've covered how this all works in the earlier videos of our 3d platformer series so take a look if you want to know how it was done alternatively you can get access to the project files of previous videos by supporting us on patreon a link to the relevant project files can be found in the description okay the first thing we need is some animations for the jump for this we'll head over to mixamo.com first of all we'll go to the character tab and select the doozy character we've been using then we'll go to the animations tab and search for a jump animation the obvious thing to do would be to select one of these jump animations the problem with this is that the jump animation is a finite length the duration of the jump in our game will take different amounts of time depending on various factors for example jumping down from a ledge will take longer than jumping on a flat surface to be able to handle this we're going to split the jump animation into three stages the jump up the fall down and the landing this way we can synchronize the different animations with the different stages of the jump fortunately mixamo has animations for each of the stages we need let's search for jump up first we'll select this one this will be used when we start the jump we'll click download and then select fbx for unity and without skin to just download the animation then we'll download this to the assets folder of the project next we'll search for fall idle we'll select this one this will be used while the character is falling through the air we'll download this to the assets folder the same as before finally we'll search for landing we'll select this one this will be used when the character lands the jump let's click download and save it to the assets folder back in unity we'll select the three new animations in the assets panel then we'll go to the rig tab and change the animation type to humanoid we want to make use of the character avatar so we need to change the avatar definition to copy from other avatar we'll then select the character's avatar as the source if any of this seems unfamiliar then take a look at our video on animation retargeting where this is covered in more detail we'll click apply to save the changes next we want to set the falling idle animation to loop to do this we'll select the animation in the assets panel and then we'll select the animation tab we'll tick the loop time and loop pose checkboxes we're going to control the movement of the jump in a script so we don't want these animations to affect the movement we can do this by ticking bake into pose for all three root transforms we'll also select original from the based upon drop downs to use the original values from the source file more information on this can be found in our video covering root motion we'll click apply to save the changes then we'll bake the transforms on the other two animations as well we need to make one final adjustment to the landing animation it currently includes the four and landing we actually only want the landing part of it so we'll change the start frame to eight now it just has the landing animation let's click apply to save the changes now we have all the animations ready we need to set up the animation states and transitions we'll select the character in the hierarchy and then double-click the animator controller to open the animator window let's right-click in the animator window and create a new empty state we'll call this jumping then we'll set the motion to the jump up animation next we'll create a falling state for this one we'll set the motion to the falling idle animation then we'll create the landing state and we'll select the landing animation next we need to create the transitions between these states we want to be able to go from idle to jumping so we'll right click on the idle state and select make transition we'll then click on the jumping state to create the transition next we'll create a transition from jumping to falling then from falling we want to transition to landing from landing we'll transition back to idle we also want to be able to jump while moving we'll rename the blend tree to moving blend tree to make it clearer then we'll create a transition from this to the jumping state if we're doing a running jump on landing we want to go straight back to running to do this we'll create a transition from landing to the moving blend tree the character could also go straight from moving to falling if they walked off a ledge for example so we'll add one more transition from the moving state to falling okay so now we have all the states and transitions created the next thing we need to do is configure the transitions for this we're going to need a few parameters we'll go to the parameters tab and add a new boolean parameter we'll call this is jumping then we'll add another we'll call this is grounded we'll add one more and we'll call this is falling we're going to make use of these parameters as conditions for transitioning between the states let's start by selecting the transition from idle to jumping we'll untick has exit time as we want to control when we leave this state we want the transition to be quite snappy so we'll change the transition duration to 0.1 then we'll add a condition we'll set the condition to be when is jumping is true so now when the is jumping parameter is set to true the jump animation will start we'll do exactly the same for the transition from moving to jumping next we'll look at the transition from jumping to falling we'll untick has exit time and add a condition for this one we'll check that is falling is true we'll then do the same for the transition from moving to falling next we'll configure the transition from falling to landing again we'll untick has exit time we'll shorten the transition time to 0.1 then we'll add a condition and set it to when is grounded is true after landing we can either go to idle or moving we'll start with a transition to idle we'll untick has exit time and add a condition we'll set the condition to when is moving is false when idle we want to see most of the landing animation so we'll set the transition time to 0.6 then we'll do a similar thing for the landing to moving transition again we'll untick has exit time we'll set the transition time to 0.2 this will give quite a quick transition and prevent the landing slowing down the character movement too much we'll add a condition and set it to when is moving is true now that's all the transitions configured the next thing we need to do is set the animator parameters from our script we'll select the character in the hierarchy and double-click the script to open it in the editor first of all we'll add a couple of private boolean fields to keep track of things we'll add one that tracks whether we're jumping and we'll add another that will keep track of whether we're on the ground then we'll go to the update method currently we check whether the character controller has been grounded recently if it has we check if the jump button has been pressed recently then we set the y speed to the jump speed if you want a more detailed explanation on this then take a look at our earlier videos on jumping so when the character jumps we'll set the is jumping animator parameter to true we'll also set that is jumping field when the character is grounded we'll set the is grounded parameter to true we'll also set that is grounded field when grounded we'll also set is jumping back to false and we'll set is falling to false in the else statement for the grounded check we'll set the is grounded parameter and field to false in here we'll also decide if the character is falling we want to transition to falling when the character goes from jumping up to down so we'll check if we're jumping and the y speed is less than zero we also want to fall when dropping down from a platform but we don't want this to happen when the character is just going downhill or down some stairs to do this we'll check if the character has built up some speed in the negative y direction we'll check if it's less than -2 then we'll set the is falling parameter to true now we have all the parameters set let's save the script and switch back to unity to try this out now when we press space the character jumps up falls and lands it's not looking too bad but there are a couple of issues firstly if we jump and then jump again quickly the landing animation is still playing on the second jump secondly if we try to do a running jump the character doesn't move while in the air let's stop the game and fix these issues first we'll look at the issue where the landing animation is playing when jumping we'll go back to the animator window let's look at the transition from landing to idol the problem is that this takes 0.6 seconds to happen and the character can be jumping again during this time we can easily fix this though by allowing the transition to be interrupted we'll set the interruption source to next state this will allow the transitions on the next state to interrupt this one so if the conditions are met to transition from idle to jumping then the landing to idle transition will stop and the idle to jumping one will start we'll do the same for the transition from landing to moving next we'll go back to the script to fix the moving jump issue the reason the character doesn't move in the air is because we're using root motion the walking and running animations move the character forward but the jump animation doesn't if you want more detail on how this works then take a look at our video explaining root motion what we're going to do is only move the character using root motion when it's on the ground then we'll add a new serializable field for the horizontal speed we want to move when jumping next we'll go to the end of the update method we'll check if we're not on the ground in here we'll then set the desired velocity to the movement direction multiply by the input magnitude multiply by the jump horizontal speed we'll then add the y speed to the velocity finally we'll move the character by this velocity remembering to multiply by time dot delta time let's save the script and switch back to unity we'll set the jump horizontal speed to 3 and press play to try it out now the player can jump multiple times in quick succession and the correct animation plays we can also now do a running jump if we fall off this rock we can see the falling animation plays our jump is looking much better now but you can really notice the transition from jumping to falling in our next video we'll look at how we can edit the falling animation in unity to make this look much better okay that covers everything for this video a big thank you to all our amazing patrons for helping to support the channel if you'd like to help and also get access to the source code you can find details in the description please leave any questions or feedback in the comments and subscribe and click the bell icon so you don't miss the next one thanks guys
Info
Channel: Ketra Games
Views: 76,939
Rating: undefined out of 5
Keywords: Jumping animation Unity, Making a character jump Unity, Animated Jump Unity, Mixamo, Root Motion Unity, Jumping animation Unity3d, Making a character jump Unity3d, Animated Jump Unity3d, Root Motion Unity3d, Unity, Unity Tutorial, unity3d, Unity3d Tutorial, Learn Unity, Indie Game Development, Game Development, Learn Unity3D, Unity 3d, Unity Tutorials, unity 3d Tutorial, Tutorial, Game Development Unity, Unity Game Tutorial, Unity Tutorial for Beginners, Unity Beginner Tutorial
Id: sJvWmFYSQFY
Channel Id: undefined
Length: 16min 2sec (962 seconds)
Published: Sun Dec 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.