MAKING RUN, IDLE & JUMP 2D GAME ANIMATIONS - UNITY TUTORIAL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to black thorn prod I'm Noah Anne in this tutorial video we're going to dive headfirst yet again into the world of 2d game animation today we're going to learn how to make cool animations by a platformer player character we'll take a look at how to make appealing and fun run animations idle animations now to make a really cool jump we'll also take a look how to make transitions between these various animations with the animator and some simple c-sharp code of course tons of all be shown and said in this video can be applied to any type of game and any kind of character now just before starting I recommend you first check out this video I made on the basics of game animation in unity there I show you how to draw animation ready characters rig them as well on how to use unities animation timeline to bring your characters to life if you know all this though or have already watched that video then let's jump right in so I made a simple Humana wide player character he's made up of a head body shield sword arm and two legs I parented all these body parts tree roots and game object called player so that when I move rotate or scale that object so all the body parts move scale and rotate with its attached to this player object is a 2d box Collider rigid body and platformer controller c-sharp script so this enables the player to be moved around the world and jump on platforms if you want to learn how to do this just check out my video on the topic however as you can see there's no animations as a result the player looks very boring so without further ado let's make an idle animation this is the animation in game characters play when standing still because obviously even when characters stand still they should still be moving a little bit so such I have their chance to rise and fall to look like they're breathing or have bits of clothing move slightly in the wind or have them blink once or twice there's only the character seem alive and not like some dead robots so I'll open up the animation timeline by heading over to window animation and animation again that's like the player rich object and choose create a new animation there I'll save my idle animation inside a folder called warrior player so first of all I'll set keyframes for the body and then move the last key frames to about frame 20 to me the idle loop a bit faster than 60 whole frames so 1 seconds then I add about frame 10 I'll move the body of the character up a bit and hitting play you'll see that the character already looks more interesting like he's breathing of course it still looks very stiff so let's add some overlapping action to this animation about adding position keyframes to the head then at frame 5 I'll move the head down a bit and that 15 I'll move it up and you can see that things look much smoother in action already of course it's very important that in this sort of animation things loop in other words these starts and end of the animation must see the character with the same position rotation and scale if not there will be some ugly snapping to make sure that the animation is indeed the same at the start and end simply it's like the first keyframes hit ctrl C on your keyboard to copy those and paste them with ctrl V at the end of your animation awesome Nick stopped us likes these sword and shields and rotate them slightly at the middle of the animation to create some more movements it's often a good idea to move each body part ever-so-slightly in an animation this makes it feel more alive and believable it's just more interesting than something static and to finalize this idle animation let's add some squash and stretch so I'll squash the head a bit at frame 5 and stretch it just a tad at frame 15 ax the more squash and stretch you add the softer and more cartoony the animation will appear so yeah I don't add too much of you want your game to look realistic and serious and that's about since we have an idle animation now let's move on to the run animation the player will be seeing a lock this one well whenever he moves left or right actually so I'll create the first pose this one featuring the character with his legs stretched apart in full swing also rotate the weapon up a bit now copy these first keyframes and paste them at the end of the animation I think I'll make it last no more than 20 frames I want this animation to be fast and dynamic after all and of course don't worry you can always change pretty easily the speed of your animation later on anyway I'll now go to frame 10 and rotate my legs in the opposite direction this way they appear to move back and forth like in a real Hrodna also rotate my sword down just a bit so I don't want them swinging it like crazy in this case same thing for these shields now the animation still looks really bad this is because we need to create the down and up pauses basically in a run there's a few key poses the character goes through the contact poses which are the ones we just created then there's the down pose and this is when the character puts his weight on one leg and squashes down a bit so just to leap in the air after that with the up pose during the up pose the character is usually a bit higher and more stretched than during the contact pose so with that saying I'll grab the character's body and move it down at about frame three and then move up seven don't exaggerate there's too much or you'll get a weird jittery up and down motion and I'll copy these keys and paste them here and now you'll see that the run animation already looks a lot better at this point you can add some squash and stretch to the character for example I'll squash the head just a bit strain the down poses and stretch it a little for the up poses and so here's my final results of course this is a simple cartoony character and creating a run animation for a more complex or realistic character will take more time and require slightly more pauses but hopefully you've understood the basics now chances are high you're not too satisfied with the speed of the animation just remember you can drag a marquee over all your keyframes to select them and then left click on this blue bar to squash your key together or pull them apart squashing them will speed the animation and pull them apart will slow it down so yeah for a character moving at this speed I think a run that goes like this is cool but of course I'll probably needs to adjust this a bit once the animations are tied in with what each player is doing in game next up we needs to make a jump so I'll create a new animation called jumper now the actual c-sharp code handles the player character moving up and then falling back down so we don't want to animate the player moving up and down with this animation that will just interfere with the code I make for some very weird jumps instead we just wants to get the player in a jump pose so legs apart and body leading slightly backwards and something to jump a bit more interesting and less static I'll gradually get those legs moving apart even more for a duration of 1 seconds as well as got the body leaning back even more and that's it this will look great in action and Dori you can always come back later and tweak your animation once you see how it fits in with the blur controller for now though we only have two animations left to make a takeoff and landing animation will play the take-off animation just before the jump this is just one pose that sees our character stretched out so basically leaping into the air this will make for a really nice cartoony stretch as the character leaves the ground for his jumper and they'll make an animation called lands and here I'll just get the character squashing slightly and then bouncing back up a bit so when the character lands back on the ground after his jump you'll squash a bit so if making the jump feel more impactful giving the character more weights and just all-in-all making everything look cooler so there we go we have five animations now we need to jump inside of the animator window and set up all the transitions between these animations and then we'll need to type some c-sharp code inside our player controller to get these animations playing at the right time but first I'll head over to my warrior player animation folder and make sure to uncheck the little time box for the takeoff land and jump animations this is because I don't want these reanimations playing over and over again I just want them playing once when I tell them to I'll leave the loop tine box checks for the idol and run animations though so that they keep playing as long as the characters running or standing still now if you've never touched to the animator window and know nothing about animation transitions then I highly recommend you check out my beginner tutorial on the topic with that saying I'll make a bool parameter called is running we'll use this to garrett culture transitioning from his idol to his run animation and vice-versa so I'll right-click on the idle animation and choose make transition and I'll connect the idle animation with the run animation now left click on that arrow to select V transition and add a parameter down here so only it is running is equal to true I wants to go from the idle animation to the run animation I'll uncheck exit time and make this transition last no more than 0.1 seconds I want the character to go from his idle to his run animation fast so things feel fun and responsive and I'll make a transition going from the run to the idle animation this one not only work if is running is equal to false and again uncheck exit time I make the transition last 0.1 seconds now the only way we can set whether is running is equal to true or false is via code I'll double click on my playercontroller script to open up inside of Visual Studio first of all we need to grab a reference to the animator component attached to the player character I'll make a private variable of type animates are called Anam and set that equal to the animator component attached to the player in the star function with that done I'll be able to say is running equal to true or false so I'm going to check down here whether move inputs is equal to zero if it is then that means my character isn't moving so I'll type an endorsee bool is running false and so now the character will play his idle animation since he isn't moving left or right so however if move inputs isn't equal to zero then that means he is moving in which case we'll say is running equal to true so that the character plays his run animation I'll save my script and test this out inside unity and indeed the character plays his idle animation when standing still and runs when he moves left or right and so at this point you can adjust either animation if need be here so for example if the run feels too slow compared to the speed with which the character moves left or right you can simply squash the keys together to make it a bit faster alright we're making great progress here next up we need to set up this jump animation so I head back to the animator window and create a transition going from this any state box to the takeoff animation box and we'll only transition to this takeoff animation if a parameter is triggered so I'll create a new parameter this one of type trigger calls takeoff and now select my transition arrow and add a new parameter this takeoff one they'll make this transition last no more than 0.1 seconds again so to recap as soon as this takeoff parameter is triggered and the character will go from any state so his idle or run states and transition to the takeoff animation states of course we don't want him staying in this takeoff state forever we want the player to quickly transition to his jump animation I'll make a new transition going from the take-off animation to the jump animation but before doing that we want to make sure the character is indeed jumping atomic a last boo parameter called is jumping and add a parameter here checking whether is jumping is equal to true I'll uncheck exit time here too and get this transition lasting 0.15 seconds and so as soon as the jump is finished I get a player transitioning to the land animation we know that the jump is complete and that the counter is back on firm grounds as soon as the is jumping parameter is equal to false and again I'll uncheck exit time and set transition duration to 0.05 I just want to make this extra fast and impactful and lastly I'll go from the land animation to the idle animation if is running is equal to false or from lands to run if is running is equal to true this time I'll leave exit time checked and set to 1 for both transitions but when I want the whole land animation to play before transitioning to the run or idle animation and then for a transition duration I'll type in 0.1 seconds awesome that should work really nicely we just needs to set a few things up via code now so as soon as the player hits the jump key which in my case is Xia that will trigger the takeoff parameter this way it goes from whatever state he's currently adds to that takeoff animation then if he's not on the ground our set is jumping equal to true tonight in transitions from the takeoff animation to the jump animation however if he is on the grounds then I'll set is jumping equal to false this way you'll play the land animation and from there go back to run or idle and that's it I'll save the script and test things outside and things look awesome the character is fully animated and feels a lot more alive and he did or we just started now again things might not look or feel that good for you at this point if that's the case then continue tweaking your animations and animation transition values for example if the character seems to take a long time to go from his idle to his run animation that perhaps decreased the transition duration value of that transition or if the land animation doesn't feel exaggerated in alpha try squashing the character a bit more it's all about practice and patience anyway thanks so much for watching this game animation video I hope you learned a thing or two and enjoy the process if you need help or want to ask me a question post away in the comment section down below and I'll try answering to the best of my ability as you may know by now the black thumb prod game jam is currently running with over 8,000 participants I myself I'd be making a game for the jam and look forward to sharing it with you when the event ends this Saturday you can of course also expect a making-of video about the creation process I went through to bring this game tonight soon enough and once that's done I'll get back to work on my puzzle platformer game so yes stay tuned guys oh and just before leaving note that you can support me and my channel financially by patreon like these epic people it's a really big help and even a dollar every month is so appreciated and encouraging just saying the like and subscribe buttons is also really awesome ok see you soon Cheers [Music] you
Info
Channel: Blackthornprod
Views: 511,340
Rating: undefined out of 5
Keywords: blackthornprod, gameDev, unity, tutorial, noaCalice, c#, programming, art, animation, game animation, 2d game animation tutorial, bone based animation, skeletal animation, spine, player character animations, animation transitions, setBool, SetTrigger, run animation, idle animation, jump animation, beginner, basics, indie game dev, platformer game, platformer controller, frame by frame animation, bone based animation in Unity
Id: FTxQKHG5WCA
Channel Id: undefined
Length: 15min 30sec (930 seconds)
Published: Thu Feb 28 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.