Hello, guys.
In this video, we're going to make lend animation.
And first I want to explain how it's going to work.
Lending going to be triggered when we get into the ground, but it's always like that.
So we need some special condition to make lending special.
So what I want to do is to make that if player going down really fast, if his velocity on the Y is
negative, like -20 or something, then we can switch on boolean that he can roll on lending and when
he touches the ground, animation will be triggered.
So that's what we're going to do.
Let's first create animation.
Let's select player, create new clip.
Animations player role.
Then we go into animations or sorry, graphics.
Should I Wait a second, I'll highlight the mouse.
All right.
So we're going to player find a role folder.
And here we need roll animation.
But not all of the sprites.
Maybe from the second one.
Yeah.
We need these.
Or even, you know what from the third one, because he's kind of flying from above.
And then there is this and roll like that and stand up.
Now let's try a sample rate.
15.
Think that's okay.
Now we're going to animator.
Let's create bowling.
Ball can roll.
Going to drag it above just like that.
Place it here and we're going to do some changes here.
We're going to make transition to roll from double jump if can roll through.
And if he is grounded, sorry, is grounded through exit time and check, Duration zero, as always,
then from jump fall, the very same.
Plus plus can roll and is grounded and check zero.
Then from player roll we do in transition to idol with exit time one and duration is zero.
So we're just going to play animation once and then we're going back to Idol move.
All right.
Now let's select our transition from jump forward to Idol move and add here.
Condition can roll false.
Same for double jump.
Can roll should be false.
All right.
We done with animator.
Now let's go to player script.
We're going to animator controllers.
Let's find the function over here.
And here we need to make just one if statement.
So it will say if rb velocity dot y less than let's try -20 then anim set ball off can role will be
set to true.
While we are here, let's create a function private void role anim finished.
And actually we can just return one line of code and said bull can roll to false.
Let's go back to Unity.
Find our player, find roll animation.
Then we go into the last frame and we add event.
Roll animation Finished.
Let's go and test this.
I prepared a level part for this.
There's nothing special.
Just a block so we can jump on the top.
Let's go and see this.
So I'm going to jump from the high ground and roll is there.
Cool right now.
There is one misbehavior we have and what I'm talking about, I'll show you right now.
If I'll jump now and I'll do my left climb, my animation role will be triggered.
So why is that?
And what is happening?
Actually, when we do in ledge climb, we did not switch of gravity scale of the player and he's always
pulled down.
We just sit in his position over here.
Let me find it.
Ronald Reagan.
Yeah.
We sit in his position to climb big and position all the time, but we did not switch of his gravity.
So he's getting pulled down all the time and his velocity in the rigid body over here, you can, you
can go to a rigid body in four and you can find his way velocity over here.
Yeah.
So we can see his negative velocity is always negative when he's doing that.
Let me try to show you again.
Look here at the velocity on the Y.
That was negative, Right?
I'll try again.
It is negative.
Going down, down, down, down, down, down, down, down.
You see?
Minus eight and so on.
And reaching up to -16, sometimes even more if you jump from the high ground.
Okay, My velocity is -12 now because I jumped from the high ground now, which it's going down, down
more and more and more and more and more and more and.
Up to -40, I can see now.
So what we can do here, we can just switch off the gravity scale while we're doing ledge climb.
That will be very simple.
Once we grab the ledge, we're going to set RB dot velocity or sorry, rb rb dot gravity scale equals
to zero.
And our default gravity scale is five.
It's over here so we can go back to code and when Ledge climb is over, we're going to do our gravity
scale equals to five.
Now let's try that again.
And now roll is not triggered after ledge climb, but it's triggered after a jump from the high ground.
Now we can go to the next video.