HOW TO MAKE ANIMATION TRANSITIONS - UNITY TUTORIAL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey I'm no creator of blackthorn prod and in today's unity tutorial we will have a close look at animation transitions using unities animator window and a bit of c-sharp so what are animation transitions well the easiest way to explain this is with an example here the character is standing idle and by pressing the arrow keys he'll transition from his idle animation to a run animation if I hit space he'll now jump so there was a transition between his run state and jump States with that said let me show you how to do this so I have this simple cartoon character with three animations shown previously idle run and jump but when hitting play you'll notice that even though I'm hitting the arrow keys and spacebar the character is remaining in his idle pose let's head over to the animator window and figure out why you can access this window right here so you'll notice that my animations are represented with these boxes one of these boxes the one entitled title is highlighted in orange and has a connection with this green empty box basically this means that this is the default animation the can't you'll play when the game starts you can change which animation in your animator is the default States by a left clicking on it and choosing set has default States for example let me do so with the run animation and you'll see that when I hit play my character will banky fault run I'll do that though with control Z Y I really want is my character going from idle to run when I hit an arrow key and from run to idle when I've stopped holding down the arrow keys so I need to make a connection between idle and run I'll right-click on the idle animation box and choose make transition you'll notice a white arrow appears I'll now click on the run animation and now the arrow links the two states if I now click on this arrow you'll notice this condition menu for now it's empty so let's make a new addition we can create one under parameters and hitting the little plus sign will have to choose between these four condition types in this case the bull condition is the best I'll call the condition is running and then select my transition arrow and hits the plus sign in the conditions menu so now when is running is equal to true my character will stop playing his idle animation and begin running of course I'll make a transition going from run to idle now and for a condition I'll shoot is running once again except this time I only want my character stopping his run animation to play as idle one if is running is equal to false and the way we set whether or not is running is equal to true or false is via code so I'll make a new c-sharp script called character animate and open it up but first things first I need to grab a reference to my animator components attached to my character so I'll make a private variable of type animator called annum and set that equal inside of my start function to the animator component attached to my character in my update function I'll now check whether the player is hitting the left or right arrow key and if he is I want the character to run in other words I want my is running full condition to be set to true so I'll type a name zebu and inside the parentheses I must type between quotation marks the name of the condition so is running and then I must state true or false and has I said a few seconds ago we want is running to be equal to true so our character plays the run animation however if my player is not holding down those arrow keys family the character is supposed to the idle and I'll copy this line of code paste it in here and change true to false heading back into unity I'll drag and drop this script onto my character and test this out and indeed the character will transition from idle to run and Bank however things in my case don't feel very responsive the character transitions from idle to run rather slowly which doesn't feel great and that's when B settings come into play I'll disabled has exit time which we don't currently need but we'll come back to later in the video the only really important setting here other than has exit time and the actual exit time which we will take a look at in just a moment is the transition duration value it's basically how many milliseconds or seconds will it take for your character to go from one animation stage to another the higher this value the more slow the transition and the lower the value the faster in other words a value of zero will see your character immediately snapped from able to run I'll go for a 0.1 just to make things look a little smoother I'll now do the same for run to idle disabling has exit time and giving my transition duration a value of 0.1 and now things feel a lot more responsive and intuitive okay let's now get our character jumping to do so we will use a different type of condition so I'll click the little plus sign up here and choose this time trigger calling it jump I want my player being able to jump at any given moment so whether he is standing idle or running he can jump has a results we can use this blue box named any States and make a transition between it and a jump animation so no matter what animation the character is playing he will be able to transition to this jump animation when the jump condition is triggered once he's played that animation however we wants a transition so the idle or run States so I'll make an arrow linking those two and leader conditions menu empty again to trigger our jump animation we must do some simple programming so when I hit the space key I'll get my character leaping in the air by typing Anam dots and instead of using same rule I'll use set trigger because remember we are using a trigger parameter to get our character transitioning from any state to his jump state and now inside the parentheses I need to do is type Biggs name of the trigger parameter between quotation marks so jump before hitting play however I'll make sure to uncheck has exit time for this transition here and to make things feel really responsive and intuitive a zero transition duration to my character hops in here immediately now let's take a look at these transitions as usual I'll set up my is running condition getting my character to play the run animation if is running is equal to true and if not get him to play his idle animation I'll also tweak transition duration and this is when has exit time comes into play and take a look at what happens if we uncheck has exit time when we hit play and try and jump the character will start playing his junk animation very quickly resumed his idle or run animation this is definitely not what we want we want our character playing his whole jump animation and only then go back to running and jumping so let me check has exit time and take a close look at this exit time value a value of 1 here we'll get our character playing 100% of his jump animation before transitioning to in this case the run animation which is exactly what we want you can of course set it to for example 0.5 and only played 50% of the animation that is really what we want so in most cases leave this at 1 I'll make sure to do the same for the transition between jump and idle and now I can press play and get my character leaping in the air awesome if your gang some strange behaviors though normally you shouldn't try disabling the loop box of your jump animation since unlike run and idle we don't want our character endlessly jumping unless we actually press space notice that there are two other condition types you can use float and int but I've never used both they basically let you play a certain animation when a float or int value is smaller or greater than X amounts so maybe I have a player would bees though again you really don't need them especially when starting out and that will mark the end of this video I hope you enjoyed it and found it helpful if you did and want to be absolutely awesome you can support me with a monthly donation via patreon like these awesome supporters and help me continue making regular gamedev contents with that said don't forget to hit the like and subscribe button that too is so appreciated alright stations Cheers [Music] you [Music]
Info
Channel: Blackthornprod
Views: 219,958
Rating: undefined out of 5
Keywords: blackthornprod, game dev, noa calice, how to, animations, 2D, 3D, animator controller, animtor, AC, ac, controller, transitions, HOW TO MAKE ANIMATION TRANSITIONS - UNITY TUTORIAL, tutorial, unity, blend, walk, run, jump, idle, conditions, bool, set bool, set trigger, SetBool, SetTrigger, C#, c#, coding, programming, make, beginner, easy, game character, game animation, character, state
Id: HVCsg_62xYw
Channel Id: undefined
Length: 9min 15sec (555 seconds)
Published: Tue May 08 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.