Idle, Run, Jump, Fall, Wallslide Platformer Animations - 2D Platformer Unity #5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in our previous videos we got our player jumping around on these platforms and doing War jumps and wall slides now we're going to add animations to all of these movements so let's get started to do animations we're going to need to add some windows so if you go up to the top and click window go down to animation animation and I'll drag this right down the bottom then go back up to window go animation animator and we'll leave this tapped here cool next we'll bring in the Sprites we want to use for our animations some of these are single frame assets I've taken from Kenny's tile map and others are ones I made myself by editing his Sprites you can get all these on my patreon if you want to use them so I'm just going to drag these into our Sprites folder in our Assets in unity double click on the hair and in this folder you can hold down control and select all our character sprites and avoid our tile map then for all of these I'm going to set them all to 16 since they're 16 by 16. filter mode to point no filter and then compression to none and click apply then I'm going to go to the ones that are multiple Sprites and hold down control so that's idle and walk for me click on these and change Sprite mode to be multiple gigabyte then individually I'll go to idle first go Sprite editor click slice and grid by cell size then set this to be 16 by 16 and click slice apply close that one off go to walk Sprite editor slice grid by sale size 16 by 16 slice apply and now you can see if we open up our idle you can see it split this into two separate Sprites we can use these as our frames in our animation for jumping wall slide in full I've just got single frames now if we go to our player click add component search for anime tour and add an animator component then while selecting our player down in our animation window if you click create and then I'm going to go back into our assets and create a new folder and this will be for our animations if we go inside here and I'll name this animation idle you can see this automatically created a controller for our player's animation if we go into the animations folder you can see we've got a player controller now as well as our idle animation we'll come back to the controller later once we've made all our animations if we go back to our Sprites folder and open up idle we can drag each of these frames into our idle animation down the bottom the diamonds in here show your frames and the numbers at the top is the time in which that frame will play so if we zoom into our player then press play you can see it's going way too fast so we can click and drag out our second frame to around 0.30 and if we press play again you can see it's kind of jittering that's because it gets to the second frame and then instantly snapped back to the first to fix this we can add another frame either the first or second place it about one you can see it speeds much better next we'll add the walking animation so under idle in the drop down you click on this and click create new clip call this walk and move back from assets into the animations folder in our new animation we can open up walk and drag in our Sprites for our walking animation we'll want to be a bit faster so I'll leave it at these 0.5 intervals and add another frame in 15 so we don't get that clipping cool next we'll do our jump so again new animation we'll call this Jump Then I just have one frame for my jump animation so we just drag that in same with the next two we'll slide drag in our wall slide frame and fold drag in our full link frame you may have noticed in our top animator controller you can see all the animations we're creating this is what we're going to set up next so we don't need this animation window anymore I'm going to close that Tab and expand this down I'm going to move these up for now now first let's get our character walking so this default entry going into idle is fine we'll bring over our walk animation so to get this animated you right click click on idle click make transition and you'll see we can have a transition going towards walking then we're going to want to be able to transition back from walking to idling for these transitions we can add conditions so to go from idling to walking when something happens to do this so under your animator tab go from layers to parameters and click the plus button then select float for walking we're going to use our magnitude so select your transition that goes from idling to walking so this bottom one click the plus and the conditions and say if our magnitude is greater than zero which is the default then in our transition from walking to idling click the plus and we want if our magnitude is less than 0.1 we're going to edit a few extra settings here so back on the transition from idle to work we'll untick has exit time open up the settings untick fixed duration and set transition duration to zero all of these settings mean that our animations will be quick acting and snap to one another we'll do the same for walking to idling untick has exit time and fixed duration and set transition duration to zero The Next Step would be to add the script and show this working but so we don't have to click around all over the place let's get the controller set up and then we'll go into the script so next let's add our jumping we'll grab our jump animation and we want to be able to jump from any state since we could be idling walking or wall sliding so right click on any state and go make transition and select Jump Then M parameters click the plus and add a trigger and we're going to call this jump now click your transition to jump we want the same settings as before so untick fix duration zero transition duration and then in conditions click the plus then change magnitude to jump that's all we need now after jumping we want to fall so we'll grab R4 animation and place it under our jump so right click on jump make transition and click on full now in this transition we do want to have an exit time and our exit time is going to be one and we'll set our transition duration to zero then our Interruption source is going to be next state so how we know when to transition from jumping to Falling will be when our player has reached their Peak and begins to fall down so that'll be when our y velocity is less than zero so in parameters let's add a float and call this y velocity and click the Plus in our conditions on our jump to four transition and select y velocity less than and leave that at zero next we'll want the same thing from idle to falling in case we walk off a platform instead of jumping off a platform so on here we actually don't want an exit time this time we do want a fixed duration and we're going to set this to zero our conditions again will be y velocity Less Than Zero now to know when to transition from falling to idling to make a transition from falling to idling we'll set this transition duration to be 0.2 just a little bit less our Interruption source of next state so we can get walking instead of idling if need be and our condition for this is going to be if our y velocity is greater than minus 0.01 an untick fixed duration cool now we have one more animation to add which is our wall slide like jumping this can be done from any state so do make Transition from any state to wall slide and select this transition this we want no exit time no fixed duration transition duration to zero and for this condition we're going to need another new parameter and this is going to be a ball we're going to call this as or sliding we'll say in our conditions select is war sliding is true then we want a transition from wall sliding to Island select this and we'll say yes we want an exit time and then set transition duration to zero and in our conditions probably guessed it is wall sliding is false now just a heads up make sure your parameters are all spelled correctly with the right casing since when we set these in our script it'll have to be exactly the same casing I'll change jump to be a lowercase j until these are all consistent cool now let's go to our script so double click on player movement and at the top we're going to want a public animator animator then down in our update underneath where we flip we're going to go animator dot set float and in here we pass in our ID so there's going to be a string or an INT but we're going to use like I said our names so first we'll set y velocity then pass in the value so that's our RB dot velocity dot y next we'll need one for magnitude so animator.saploat magnitude and pass in RB dot velocity dot magnitude in here we can also set our animator dot set ball set R is wall sliding since we already have a ball called this wall sliding cool now the last one we'll need is down in our jump function after we jump we want to set our animator dot set trigger and then we pass in Jump oh and we set that to a lowercase j and make sure your casing is right if we highlight this and press Ctrl C to copy then down where anywhere we jump we'll paste this in so when we do a light tap we jump then when we will jump we jump so we'll paste this in here as well and that should be it back in unity when we press play if you're in focused mode you can watch our controller switch between our different animations so if I walk and jump and fall you'll see it's moving so here we can see our player walking if I jump you can see it does a little jump animation which is like a pretty little ballerina leap and as we fall puts his little arms up now let's test our wall sliding so if I just wall jump up a bit oh you can see he does that cool little Spiderman and grapple there we go on patreon you'll be able to get this package for our character's animations and controller so check it out if you want if not see in the next one where we'll be looking at particle effects to add even more interest to our character I'll see you then [Music]
Info
Channel: Game Code Library
Views: 2,089
Rating: undefined out of 5
Keywords: platformer, game development, player, unity2d, programming, tutorial, unity 2d tutorial, how to, beginner game dev, easy, how to animate unity, animation tutorial, 2d player animations, 2d game animation tutorial, player character animations, game animation, idle animation, platformer game, platformer controller, run animation, unity animation 2d, jump animation, unity flip sprite animation, animation transitions, animation, unity animator, blend tree, unity tutorial, wall slide
Id: vFYQ3Ge4XvY
Channel Id: undefined
Length: 9min 40sec (580 seconds)
Published: Fri Sep 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.