Hello, guys.
Now that you are familiar with the animations, I'm going to make something more at once.
We're going to use a blend tree.
Blend tree allows you to blend between animation according to different parameters.
It can be used for 2D games just for jump and full animation, or it can be used even for 3D movement
to the eight different directions.
But today we're going to use simple one.
Before we do that, I want to explain how jump and fall animation works in 2D games.
So most of the time in the games, even like Mario or a boy, there is just a couple of frames for rise
and Jump and for falling.
It's done for different purposes and one of them is just to make your jump feel instant, because in
the platformers jump is one of the most important aspects of the game and you want to see a jump work
immediately, something like that.
Let's go to graphics folder, open jump and we can see we have only jump and fall here and how it's
going to work.
You already know we're going to have an X and Y.
So this is our Y and this is our X, right?
And our characters are going to be here.
And then when we press the space, we increase his velocity on the Y.
So he goes up and when we're doing that, he's going to be in the rise in animation in this one.
Then when he reaches highest point, he's going to go down and in that moment, velocity of the region
by then the Y going to go down and we're going to change the animation to the fall to the second one.
So first let's create two animations, create new clip assets, animations, player jump, drag the
sprite and create new clip player fall and drag second Sprite.
Now in the our animator, we can see we got two new animations but we're going to delete them.
Click right button create from new blend tree.
We're going to go over here and rename this blend parameter to Y velocity.
Cool.
Now we can take this bland tree and also rename it, and let's make it as a jump full.
Now we're going to go inside of this blind tree, and we can do that by clicking twice on it.
We are inside the blind tree.
And here we can add two motions hit plus icon, choose, add motion field and one more.
There's going to be a player full and player jump.
If you don't have this window over here, you just need to drag your mouse from here and find it.
Now let's uncheck out to my threshold and for the full animation, it's going to be minus one.
For the jump, it's going to be one.
So basically now if we drag this y velocity to the left, to the negative value, we can see we are
in full animation.
If we drag it to the right side, we can see we transferred to jump animation, right?
So it works like that.
And now we're going to control this velocity of the animator in code.
Let's go to the script, find our animation controllers function and just type any set float of y velocity
to RB, dot velocity dot y.
Very simple.
Let's go back.
Okay, now we have this blind tree, but we don't have connection to player, idol and player move.
So let's make it and to make it easier for us.
Right now I want to drag this gray box which says any state and just make transition from any state
to jump full.
It means we can.
It means what?
It means we can transfer to this animation from any state that we have in the animator.
Now we need a condition for that and I guess it's best to use boolean that we already have in the code
is grounded.
Let's create this boolean in the animator is grounded.
Make transition to jump full if is grounded.
True.
And here I want to show you a handy trick.
As you've seen when I hit plus icon, my first condition chosen is running.
It is because it always chooses the first one in the list.
So whenever you work with a new parameter, what you can do is just drag it on the top after creating
it.
And now every time you click condition, it's going to be on the top.
So it's ground that should be false.
Lets and remove transition duration.
Now let's make another transition to player Idol.
Let's uncheck exit time.
Duration zero and condition will be is grounded.
True.
Now let's go back to code and add this boolean here.
So I'll type anim set ball.
Is grounded.
Two is grounded.
Make sure this name is exactly the same name that you have in the unit over here.
This is very important.
This is how it will find each other.
Now if we go to play mode.
And I jump.
I can see I'm jumping and fallen.
And if I'll run and then jump.
Still works the same.
Isn't it cool?
Very cool.
I like it.
All right.
That's it for this video.
And I have a challenge for you in the next video, so let's move there.