‫In this video.
‫We're going to take care of the animation of our character.
‫And so let's go ahead and create a character.
‫So let's go to assets and create a new folder and let's call that one character.
‫And within that folder, I want to drag my character into it because in here we'll be the character
‫and the character animation as this character prefab is a different one than the one that we had from
‫the asset store because we have changed some things already.
‫We, for example, deleted the controller, the animation animation controller, we created a new script
‫and so forth.
‫So now let's go into the character folder and create a new animation controller, because whenever you
‫want to animate an object, then you need to have an animation controller.
‫And I'm just going to call that one char anim controller.
‫So char underscore anim underscore controller.
‫You could choose a name that you prefer, but char anim controller is pretty precise of what this does.
‫So now let's open that up and I want the animator control to be full screen.
‫So I'm going to drag game into that and I'm going to go to animator.
‫All right.
‫So we have here several states already.
‫We have the nanny state.
‫We have an entry point and we have an exit point.
‫And those are the ones that are automatically created whenever you create an anim controller.
‫So the one that we need now is a new state.
‫So we can create a new state any time by right clicking into this field and then creating a state.
‫And we're going to create an empty state.
‫As you can see, there is already a transition created for us from entry to new state.
‫Entry is the point whenever our animator awakes, which means whenever our player awakes, that's when
‫the entry point is.
‫And then it goes directly via transition to any state.
‫Now if we click on any state, we should change the name because the animation or the state that we
‫want to have is run, which means we want the player to have a run animation.
‫And the beauty is that the motion that we need for that, so the actual graphical animation is already
‫there.
‫It's this animation clip called Run.
‫You could have walk jump down all of those.
‫These are the ones that we have within our asset that we have downloaded.
‫But the one that we want to use is run.
‫So let's simply start that motion and now let's open up, run so we can have a better look at what this
‫does.
‫So double click on run here in the motion on the right hand side and you will find it here under common
‫people and animations for our Super Saiyan character free pack, free sample.
‫So let's have a look at run.
‫Let's edit it and what we can see here.
‫There are several informations and what is important for us is the loop time because that one is activated.
‫That means that our player will constantly have an animation that will repeat this piece here multiple
‫times, and the length is 0.667, which is 0.66 7 seconds.
‫So after a two thirds of a second, this animation will be done and it will repeat itself as soon as
‫loop time or if loop time is activated.
‫So let's deactivate loop time and let's have a look at our game.
‫So let's run it.
‫So now let's test this with our character.
‫So let's go to our character and let's drag the chart and controller that we have created into the animator.
‫So that's our controller that we have created here, and it will go from entry directly to run.
‫So let's have a look at how this looks like.
‫And we can see the player runs and runs and runs and even if he falls, he doesn't care.
‫He's always going to have this run animation, which is not perfect.
‫We will change that later on.
‫So as soon as he falls, we want to have a different animation, of course.
‫So let's go back to our controller and actually I want to go to the run animation again.
‫So in here the run motion, I want to edit that and I will deactivate loop time now.
‫So let's go ahead and run the code again or run our game again.
‫As you can see, loop time is still activated.
‫So I'm going to apply the loop time to deactivate the loop time and I'm going to start.
‫And you can see he had one run of this run animation or one repetition, and then afterwards he didn't
‫run anymore.
‫So that's what this loop time is for.
‫It's really important that we leave that activated because what it does, it will repeat this animation
‫very nicely and our player will run beautifully.
‫So now deactivated it, of course, again.
‫So let's run it again.
‫Let's apply that, by the way, to our run FB X and let's run it again.
‫Now you'll see he will constantly do this run animation.
‫So now let's see what happens if we have the game open and at the same time we are here within our run.
‫By the way, if you want to move that around, you can press your middle button, middle button in your
‫mouse.
‫So now let's run our game and see what happens.
‫And as you can see here, this blue bar at the bottom of our run state is the repetition or the current
‫position of the animation and or of the motion.
‫So that's what this two thirds of a second is, pretty much so one run, one repetition of run is two
‫thirds of a second.
‫All right.
‫So now we have the run animation, but that's not it.
‫We need another animation as well, which is our falling animation.
‫So whenever our player is falling, we want to have the following animation and we can create a new
‫state here, create empty.
‫And that state is going to be called.
‫Falling and the motion for that is going to be jump down.
‫So we have the jump float to jump up to pick up and so on and so forth.
‫And the one we need now is to jump down.
‫So what it does, it will jump down, actually once again jump down.
‫So now we need a transition from run to falling because you can consider this as a flow.
‫So the animation starts at the entry, then it goes to run, and then at one point it will go to falling.
‫So when ever the player is falling down, we want to fall in animation to run.
‫So we need a transition, make transition and then we can drag that over to falling and now we can connect
‫it directly.
‫So in here you have a transition from run to falling in the inspector.
‫You can see it straight away.
‫And what we now need in order to know when this transition should be triggered or should run, so whenever
‫falling should change, we need to add a condition and in order to add a condition, we can do that
‫here.
‫We need to have a parameter.
‫As you can see, we don't have any parameter yet.
‫We need to create a new parameter for that.
‫So on the left hand side, you can see here layers.
‫And then there is this parameters piece.
‫So click on parameters on this tab and then on the plus sign.
‫And now you can choose from four different parameters float, int, bool and trigger.
‫And in our case we are going to use the trigger because what we want is whenever our player does not
‫have any physical on the ground anymore, so any physics body under below him, we want this trigger
‫to be set and we can do that quite quickly.
‫So let's create this trigger and I'm going to call this trigger is falling.
‫And now let's click on the transition here on this little arrow or this little line with the arrow and
‫now we can choose is falling as its condition.
‫So let's enter that, by the way, if you want to see the is falling animation.
‫You can see it here, or actually that's the running animation.
‫So let's see the falling animation, the jump down animation.
‫You can see this is the jump down animation.
‫Now we need to set is falling set this trigger somewhere.
‫And the best position to do that is our code, which means we go back to our script.
‫So let's go to our character, let's go to char control, character control.
‫And within the update method, we are going to check if we are still hitting the ground.
‫And for that we will need a new variable here.
‫Actually two new variables.
‫One is public.
‫So let's create a public one public transform rate start.
‫Because what we'll do, we'll run array from the bottom of our character and see if we hit any physical
‫body or if you still hit something.
‫And if we don't hit it, then we want to trigger.
‫Of course, then we need an animator, so private animator and so I'm going to call it and within the
‫update method, I will need a red cast hit.
‫What that does is it's a structure used to get information back from a red cast.
‫So it's a red cast that we cast to watch the bottom of our player and then we check is there something
‫or not?
‫And I'm going to call it hit and now I can do an if request here or I can add an if condition, if physics
‫dot recast and in here I give a position, a direction, an out, which is not this one.
‫So there are several overloads here, plenty.
‫We're going to use one of them.
‫So I'm just going to enter the parameters now.
‫One is Ray Start, which is our transform variable which we created here Ray start dot position.
‫So that's the origin from the ray where the ray should start then where it goes to.
‫And I'm just going to use minus transform up, which means it's transformed down.
‫So go down.
‫So the direction of the ray, then we check the out, which is simply going to be our hit.
‫So the ray cast that we have created there and then we need the length of our ray cast and I'm just
‫going to use math f dot infinity.
‫So it should go down and down and down whenever that is false.
‫So that means there is nothing that we hit.
‫That's why I used this exclamation mark at the beginning.
‫So I say not physics ray, cast transform, etc. which means if there is no hit towards the bottom,
‫then please set the trigger of my animation.
‫So please go ahead and do anim dot set trigger and which trigger.
‫Well the one is falling that we have just created.
‫So now of course we need to set our animator because currently we don't do that.
‫We need to initialize it within our awake method.
‫So enum is get component and component is called animator.
‫Now before we test that, we of course need a ray start and restart is a transform component.
‫So let's go to our character and let's create a new empty object, which I'm just going to call our
‫Ray start.
‫And the restart, as you can see here, is at the feet of our player and I want it to be maybe in the
‫middle of our player.
‫So just add the stomach or the chest somewhere.
‫So that means that it's inside of our player and that's where the ray will start and it will go down
‫and now it will check if there is something at the bottom of him or not.
‫Is there something so meaning is there a box that we collide with or not?
‫All right.
‫So now that we have that, we can assign Ray start to our chart controller and let's drag that in there.
‫Now we have a transform and now we can check the code.
‫Let's run that and see if our animator changes, but we can see that it does indeed change.
‫Maybe that's not the perfect one.
‫So let's have a look at our animator.
‫Jump down is the one that I have used.
‫So let's see if we find a better one.
‫Let's go ahead and try different one here, different motion.
‫Let's try jump float.
‫So let's have a look how that will look like and we can see I think that's much better.
‫So that's our falling animation.
‫So that's the animation that will happen whenever the player is falling and dying pretty much.
‫All right.
‫So in the next video, we are going to have a look at how to start our game, because now it just starts
‫whenever we press the run button.
‫But we need to do it better.
‫Let's save the scene and see you in the next video.