Total Animation Solution: How To Create And Manage Animations In Unity 2020

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Thanks for taking a look at my tutorial!

This channel is fairly new, and would appreciate any support I can receive; if you're able, please consider subscribing and liking the video as it really goes a long way to grow the channel.

Also, if you're interested in making a Metroidvania style game, consider taking a look at my course on Udemy that covers everything for these types of game (too many features to list in a post); visit my website to receive the course at it's lowest cost ($9.99): https://err00rfree.com/metroidvania-toolkit

👍︎︎ 2 👤︎︎ u/I_Am_Err00r 📅︎︎ Feb 01 2021 🗫︎ replies

Great tutorial :D subscribed!

👍︎︎ 1 👤︎︎ u/Perfect_Exist 📅︎︎ Feb 01 2021 🗫︎ replies
Captions
hey how's it going everyone this is i am air and i want to make a video for new game developers who are struggling to make fluid animations as well as help you understand how the animator component within unity works so that we can easily manage different animation states and depending on the animation blend between two different states i will admit it's a lot more fun to make animations than it is to manage them but hopefully by the end of this video you'll have a good understanding of how we can utilize parameters within the animator component as well as understand when and how to use a blend tree and i'll show you how we can manage the different animation states to make it look organized like this as opposed to having a nightmare like this the technique i'm going to show you on how to manage the animation states will consolidate all the different animation transitions between the any state box and then we'll set up some very simple bool parameters within the animator component and then make sure each animation plays when their corresponding bool is true and that these animations stop playing when that bull becomes false this more basic approach to managing animation states is going to be a lot easier for new game developers to wrap their mind around but still robust enough to have total control of the animation states it just might require a little bit more creativity on the game design side as opposed to the programming side so without any further delay let's go ahead and get started now as you can see i have a very simple scene that only contains a main camera and a 2d character the character is fully rigged with ik setup and if you don't already have a rig character that you can work with check out my previous video in which we rigged this character with iks to get started creating animations we first need an animation window and to get an animation window go ahead and click on the window drop down at the very top of the unity editor about halfway down you should see an option for animation if you hover your mouse over that it'll give you a couple more options to choose from let's go ahead and choose the animation window not the animator window and a new window should pop up i'm going to go ahead and dock this window on the same panel that i have my game window on and with the 2d character selected in the inspector window you should see this create button in the animation window light up let's go ahead and press the create button and the next thing unity is going to want to do is have you save these animations into a folder so let's create a new folder and let's name it animations and then let's open up the animations folder and then let's name this animation walk once we create the first animation the 2d character should get an animator component attached to it for now let's go ahead and work on the animation and later this video will go ahead and revisit the animator component to create animations we need to first hit the record button in the animation window with the animation window recording any changes we make to the player will be saved within the animation itself so what we want to do is change the rotation and the positions of all the body parts on the character to simulate a walk the easiest way to do that is to use our ik points and change the position and rotation of these body parts at the key points within the animation and then let the game engine go ahead and fill in the gaps between those frames to fluidly have the different body parts rotate and move around to form a walk and of course this is going to make a lot more sense once i actually show you what i'm talking about so what we want to do for the first frame of our walk animation is position the legs and the arms in mid-step so what i'm going to do is go ahead and put the right foot behind the character and the left foot in front of it and i'll basically do the same but for the opposite arm so the left arm behind the player and the right arm in front of the player and a couple things you should know to make animations look a little bit more fluid try to have each of the limbs slightly bent and avoid fully extending any limb when animating and i've also found it best to go ahead and handle animations one thing at a time so right now all we're doing is positioning the feet and hands and then once we get solid positions and rotations for the feet and hands we can then go ahead and start working on having the player bob up and down as they take each step as well as controlling the head movement to give it a little bit more character once you have your opening frame of the walk animation done we want to go ahead and move the timeline to the end of the animation and this animation should be about one second long so go ahead and click on the one second mark within the animation window and then let's go ahead and click on this top keyframe at the zero second mark let's copy all these keyframes by hitting ctrl c and then let's hit ctrl v to paste them at the one second mark next let's click on the half second mark which is going to be this 30 here and then let's move the position of the arms and legs to the opposite of what they currently are so have the right leg in front of the player the left leg behind the player and then the right arm behind the player and the left arm in front of the player once you swap them out go ahead and hit play to test out the animation and it should look like your character is skiing or something like that and what we want to do to get a more realistic looking walk is go to the quarter second or 15 frame mark and have the back foot raised as is coming towards the front and then make sure the front foot stays planted down as it moves behind the player and keep in mind try not to have the limbs ever fully extended when you're doing this now let's go to the three-quarter second mark and do the same thing that we did for the quarter second mark let's hit play to take a look at the animation again and i mean it's not a perfect animation quite yet but it definitely resembles a walk a very stiff one at that and so what we want to do now is go ahead and start focusing on having the player bob up and down as they take each step and when both of the feet are planted down the ground we want the player to be positioned low and then at the quarter second and the three quarter second mark when the player's step is at its highest we want to go ahead and raise the player up and the way we want to go ahead and do this is actually grab the hip bone itself and then move it into the correct corresponding positions so at the 0 30 and 60 frame marks we want to move the position of the player downwards and then at the 15 and 45 frame mark have the player's position go up and for the 0 and 60 frame mark we basically want to have the exact same keyframes so make sure after you've animated your player bobbing up and down that they still match and it's as simple as copying the first one again and pasting it on the 60 frame mark or vice versa and copying the 60 frame mark and pasting it on the zero frame mark so pause the video here if you need a little bit more time to perfect your animation again this animation isn't perfect because i'm trying to make it for this tutorial but as you can see with the bob it does make the walk look a little bit more characteristic and the last thing we can do is go ahead and tilt the player forward a little bit so at the zero second frame mark i'm going to go ahead and grab my head ik and move it forward a little bit to give it a forward tilt tilting the character forward gives it the appearance of momentum but now the character's head bob's a little too much for my taste but everything else looks good enough for this video so i'm going to go through each keyframe and adjust the head's placement and rotation to minimize its movement go ahead and scrub through each frame and see if there's any other changes you want to make but if you're satisfied with the way the animation looks go ahead and press the record button on the animation window to stop recording keyframes now that i showed you how keyframes and tweening works if you want to go ahead and start making the rest of your character animations go ahead and pause the video here i'm going to take a quick break to make three unique animations so that i can show you how we can use the animator component to transition between the different animations all right i made three random animations as you can tell they're not fluid like the walk animation i just made them to have three different animations hopefully you made different animations for your character that would actually relate to gameplay such as jumping but regardless of what types of animations you made the logic to switch between animation states is the same regardless of what your animation looks like so if you don't already have one open let's go ahead and create an animator window and to open up an animator window click on the window drop down hover over animation and choose animator this time and i typically dock my animator window on the same tab as the scene window so let's go ahead and dock it there let's click on the animator window to take a look at it and you'll see these different colored boxes with the brown line going from the green entry box to the orange walk box now the entry box is going to go ahead and trigger whatever the first animation should be when the scene loads and basically it's just doing this as a default if the parameters or conditions for another animation make more sense it'll immediately switch that animation once the game starts playing but in order for the animator component to work it needs at least one point of entry most people have an idle animation as their entry animation but you as the game designer will choose whatever you want for the opening animation what we want to do next is set up different parameters that'll tell the animator component what animation it should play here based on what parameter is true so kind of towards the top left of the animator window you should see a plus symbol let's go ahead and press that and then select bool double click where it says new parameter to rename it and then let's name this bull parameter walking next let's right-click on the any state box and select make transition a white line with the triangle in the middle of it should appear from the any state box go ahead and drag it to the walk animation box and then press on the walk animation box to have that transition go from any state to walk and then press on the white triangle to set up the transition let's go ahead and expand the settings tab for this transition i don't want to confuse you and go down any rabbit holes by explaining what these different options mean so what i'm going to do is show you how you can actually get it set up just to speed up this video and not overload you with too much information let's go ahead and uncheck this box for can transition to self and then if we scroll down to where it says conditions let's hit the plus symbol and a new condition should pop up that says walking and then true and what we just did is created an animation transition from any state to walk and what this transition is going to do is make sure that the walking parameter bool is set to true and if it is it's going to go ahead and allow the walk animation to play let's create a new boot parameter for the animator window and i'm going to name this bull parameter testing one if i had another animation like jump i would go ahead and name this parameter jumping because ultimately we're going to reference these bools by string reference and we want to go ahead and give these bool parameters names that would make sense so we can easily remember what to call the string reference and code go ahead and quickly pause the video here to create parameters for the rest of your animations and then just like we did for the walk animation let's make transitions from the any state to those different animations let's click on that white triangle to change the parameters for that transition and then for each one make sure you uncheck that box for can transition to self but when adding the condition make sure you choose the condition that corresponds with that animation don't worry about any yellow errors that might pop up in your console window what we want to do next is to create a script in which we can assign input to have the different animations switch between each other for this example i'm going to create my own script and basically this script is going to check for input and based on whatever key i'm pressing it'll play that corresponding animation and i'm just doing this to show you an example of how you can go ahead and control the different animations through script you should probably assign your different animations in their own respective scripts so for example i have this walk animation if my 2d character had a horizontal movement script attached to it i would control the walking bull through the horizontal movement script and then if i had a jump animation i would control that jump animation through the jump script so this script i'm about to create is just to show you an example of how we can transition between different animations the script i'm making is just a testing script for this video so i'm going to make a new script i'm going to name it animation test and i'm going to open it up and regardless if you're using a testing script or one of the scripts you have for your game we need a reference to the animator component so that we can change the different bool values and transition between the different animations so let's make an animator reference variable and i'm going to name this variable anim let's go ahead and define the reference in the start method so let's type out anim equals git component and then with an angled brackets animator and then within the update method i'm going to have a series of different text inputs that'll change the animator components bool values from true to false so inside the update method i'll type out if and then within get parentheses down and then inside the parenthesis i'm going to type out key code dot q and of course this if statement is going to check whether or not the q key is being pressed down so inside this if statements curly brackets let's go ahead and add some logic let's type out anim dot set bool then inside parenthesis and quotation marks i'm going to type out walking and this walking is a direct string reference to the walking bull that we made in the animator component so i have to spell it out exactly as i have it in the animator component then outside of the quotation marks i need to add a comma to set the bool value and i want the walking bull to be true when i hit the q key so all i need to do is type out true and then close out the parentheses here i'm going to duplicate this three times to make sure the other three animation bools are all set to false and i'll change the string reference from walking to testing one and i'll do the same thing for all the other string references for walking but instead of renaming it to testing 1 i'm going to rename them to testing 2 and 3 respectively i need to make sure that the rest of the bool values are all set to false so i'll also change the value from true to false for all the different bools let me go ahead and duplicate this if statement three more times i'll change the input detection for the first one from q to w on the second one from q to e and then i'll change the last one from q to r i'm also going to go down the list and change the bool value from true to false for each animation and make it so that each input detection will only have one animation state set to true and make sure that the rest are set to false now with everything set up for my testing script i'm going to save the script and go back into unity to test it out i need to remember to add the animation test script to the player and now when i hit play the character will automatically go in the walking animation because of the entry box but depending on what button i press on my keyboard it'll go ahead and quickly change between each animation and if we take a look at the animator component you can see as i hit each button the animation fires off from any state to that animation and that blue progress bar that fills up in the animation block is the animation length and where it's at currently in the animation before we wrap up this video i want to go over one more thing and quickly discuss blend trees and how we can transition between two different like animations based on a float value typically i use a blend tree for horizontal or vertical movement so that as the player starts to move faster they transition between the walking to the sprinting animation as well as when the player starts rising and falling they transition between the jumping and falling animations so let's right click anywhere in the animator window hover over create state and then choose from new blend tree one quick thing you should notice is that when i created this new blend tree it made a new blend float parameter in the parameters list and we'll be using this value to transition between different animations let me show you how we can use this blend float value to manage that transition so i'm going to double click on this blend tree then click on this box that says blend tree and in the inspector window i see this empty list for motion i'm gonna hit the plus button and select add motion field and then i'm gonna do it again and what it's looking for for the motion is an animation to play so for the first animation i'm gonna choose test one for this example and then for the second motion i'm going to choose test 2 now i need to go back to the default screen for the animator window so i'm going to click on this base layer tab at the very top of the animator window and then i'm going to make a transition from any state to the blend tree i'm gonna first uncheck the box for can transition to self then i'll add a condition and then select blend and then leave it at the default settings there now i'm gonna go back to my animation test script i'm going to create a quick float variable named test float then i'm going to remove all the logic inside the if statements for the e and r key codes and i'll replace the logic for the e key code to test float plus equals 0.1 f as well as i'll replace the logic inside the r key code to test float minus equals 0.1 f then under that if statement i'm going to go ahead and type out anom.setfloat and then within parentheses and quotation marks blend then outside the quotation marks comma test float and what that line of code is doing is it's assigning the blend float value in the animator component to whatever the value we have set for test float within this script so if you were doing this for a horizontal movement script then it would make sense to assign the blend value to whatever your current speed is and same thing with jumping and falling you would assign the blend value to whatever the falling or jumping speed is then the blend tree will go ahead and properly transition between the two different animations based on whatever that float value is and to show you what i'm talking about let me save the script and go back into unity and now when i hit play the character still goes into the walking state because it's the point of entry but once i hit e it starts playing the testing 1 animation and as i keep pressing e and the value of blend goes from 0 to 1 unity will go ahead and play both animations as a blend as it transitions between the value from zero to one and it's choosing those two different values because that's what we currently have set up in the blend tree and if we want to change the threshold values all we have to do is double click on the blend tree in the animator window then click on the box that represents the blend tree uncheck this box for automate thresholds and then you can set up the thresholds whatever you want from here all right that'll go ahead and wrap it up for this video if you learned something new or you found the information in this video useful please consider subscribing to the channel and hitting the like button as you probably heard from other people on youtube we can't stress enough how much this helps us so again if you learned something new or found the information useful please consider either liking subscribing or doing both preferably and one last quick thing i want to mention i have a highly rated course on udemy that teaches you everything you would need to know to make a metroidvania style game so if you're using the information in this video to make a metroidvania consider taking a look at my course on udemy and visit my website for a discount to the course that's enough self-promotion for this video i definitely appreciate you watching it nonetheless and i hope all you all have a great rest your day see you in the next video
Info
Channel: I_Am_Err00r
Views: 11,668
Rating: undefined out of 5
Keywords: Unity, Game Design, Game Dev, 2D Platformer, Indie Game Dev, 2D Character, 2D Character Rigging, Skeletal Animations, 2D IK, IK, Character Unity, Tweening, Animations, State Machine, Mecanim, Animations In Unity, Key Frames
Id: tysuunwI3oM
Channel Id: undefined
Length: 19min 3sec (1143 seconds)
Published: Thu Nov 05 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.