Hello, guys.
In this section, we're going to improve character.
As I told you in the beginning of the course, we're going to make layers for the game.
And that's what we did actually.
First, we created Simple character, then we created simple platform and load generation.
Then we created a background.
Now we're going to improve character, then we're going to improve platforms and so on and so on and
so on.
And as I said, let's do character first because this probably most important.
All right?
So what I want to make in this video is a double jump.
Let's go to the code of the player and we're going to do very minor changes here.
First, let's go over here and create a boolean private bool can double jump right this all what we
need basically for now.
Then I'm going to go to our check input over here and I want to change it a bit.
First, I want to take this line of code, click alt, enter and make method out of this.
So we're going to do extract method and I'm going to name it as jump button.
We need it like that because later we're going to use same function for mobile controls, but they're
going to be later.
All right.
So now let's take this is grounded and just delete it from here and then we're going to go to jump button
and type if is grounded.
Then we jump like that.
Oh, sorry.
I lost my ear.
Then we jump like that, and we're going to make a double jump.
Equals true.
Then we're going to make elseif statement.
Else if.
So basically, if somebody pressed John Button and player is not on the ground, we're going to go further
to this code.
And in here we're going to check if can double jump true.
Then let's just duplicate this line of code over here.
And we're going to set can double jump to false.
So if it was called for once we set cannibal jump to true and we cannot use this if statement anymore.
And basically it's going to work only once.
And then when we lend it and we jump from the ground, we're going to set can double jump to true and
we can do double jump again.
And let's go and see that.
Let's go back to unity.
What I want to do before testing.
I want to open, rigid body and set gravity scale to maybe, I don't know, five and jump fours.
Let's make it 18.
There's going to make a player heavier.
But if you want, you can tweak this parameters.
So let's go how it feels.
I think that's OC more dynamic.
You can make it like gravity skill more maybe six and Jump Force 22 to make him like that.
Actually it feels nice, but let's keep it like that.
So watch this.
I can jump one time from the ground and if I press double jump, I can jump again.
But if I press it a couple of times, I cannot do that.
So only double jump works, which is cool, I guess.
Right now I want to make animation for double jump to make it look better.
Let's go.
And I lost my animation window somewhere, so let me go to window animation.
Animation, drag it here and we're going to create new clip.
Animations.
Player.
Double jump.
Save it.
Let's go to project.
Graphics player.
There is a front flip animation and we're going to take it.
But not everything.
Let's see from the fifth sprite till the last one.
I'm not sure how it's going to look.
And I'll set sample rate to 25.
Quite fast.
Let me try.
18.
Now we need to see it in action.
All right.
Okay, cool.
What I want to do next is to go to assets animations, find this player double jump and uncheck loop
time, so it will be played only once.
Now we're going to go to animator.
We have this player double jump.
Just want to change the name with a capital letter.
Just for some reason I want to do it and we're going to do transition from jump fold to double jump
if and we need to create a parameter here, boolean and double jump.
Arm with upwards.
So it will be first in the list so we can do it if can double jump.
False.
My logic here is that we transfer into this animation if we used double jump.
So we cannot do double jump again and it's false.
And we should transfer to double jump animation.
Right.
Exit time and check Duration zero.
And then let's make another transition back to Idol move and check exit time.
Duration zero and condition will be is grounded.
True.
All right.
Now, that's not the end.
We need to pass this value in the code.
So let's go to player script again.
Find animator and just type here anim said Bull.
Ken, Double jump to Ken.
Double jump.
Just like that.
Now it's going to work, but we're going to have one bug and I want to show it to you first.
So, you know, you are ready for these kind of situations.
So let's go to play mode.
And I'm jumping one, two, and I'm not transferring.
So why is that?
It's happening because you can see in the animator I'm transferring to jump fall.
And that happens because we can transfer the jump fall from any state.
So what animator does is Let me try to do that.
So what's happening here?
We did transfer to double jump animation, but because we can transfer to jump fall from any state,
we did transfer to jump fall again real quick.
So what we need to do here is to select this condition and add can double jump True.
So we can transfer here only if can double jump true.
Now let's go and see that in the action.
Boom, boom.
They're a pretty right.
No, I think animation could be slower, but I'll leave it for now because I want to see how I'm feeling
about this later on in the game.
But now it's quite dynamic.
What I want to change here actually is the power of double jump because I don't like when player and
even me personally uses double jump all the time.
Like it's the main tool to go across the level.
I like to use it like a stepping stone, like a small jump that can save you in difficult situations
but won't be your main use, let's say.
So for that, we're going to go to player again and we're going to create.
Private float.
Double jump horse.
And I guess it should be sterilized field.
Sterilized field.
Let's move it up.
And we're going to create one more value.
Private float.
Default.
Jump Horse.
Now we go to start function over here and we say default jump horse equals to.
Jump force.
That's good enough.
Now let's go to John Button and when we press jump for the first time, we're going to make sure our
jump force is equals to default jump force.
But when we press double jump, we need to do jump.
Force equals to double jump force just like that.
Now let's go back to Unity.
Find double jump force and set it to something lower.
Maybe like 12.
Let's go to play mode now.
And I'm going to jump once and like a little hop over there.
Maybe a bit more.
Yeah.
Cool.
I think it's cool.
I don't like that in the inspector.
I see jump Force as a double jump force.
So let's go and change something in the code just by a bit.
We're going to move this line of code over here.
So we're going to change it back to default right after we did the jump.
Uh.
Yeah.
Now, it's always the same in the inspector.
So this is good enough, I guess.
Maybe higher.
Yeah.
Let's keep it at 13 for now.
And maybe later we decide to change it.
Maybe not.
Who knows?
It's, you know, it's never finished.
You always said we are in developing process.
We are testing and seeing how it feels.
Good.
Now let's go to code and see if we can clean up anything there at this moment.
So I would like to move this over here and.
And.
Actually.
Actually, there is a way to make it cleaner.
I don't know.
Why don't we just type here, double jump force instead of jump force and delete this and this.
And this.
It was a bit silly of me, I guess.
I don't know.
I just used to have default value in for different purposes, just in case.
This should work the same.
And let me see something else in here.
Yeah, it happens.
Sometimes you don't see best solution at first and then you just.
It appears to you.
Happens with everyone.
Right?
I hope you can forgive me.
Let me see if it works the same.
Just supposed to.
Yeah.
Cold.
Better and cleaner.
Good.
Good job, guys.
Let's go to next video.