Hello guys.
Welcome to the video.
In this one I'm going to show you how to make Coyote Jump.
For those who never heard of a coyote jump, let me explain real quick.
So.
Usually character can jump when he's on the ground.
And if player stands, for example, somewhere here, he's still detecting the ground and he can jump.
But if he'll move over here, he won't be detecting the ground and he will not be able to jump, which
is pretty much okay, I think.
But we can improve the feeling of the game by adding a coyote jump.
And this will work basically like a small delay before we take ability to jump from the player, and
with the help of that, he'll be able to jump from this position or maybe even from this position over
here.
And because of that, it's going to feel like he jumped straight off the edge, you know, like he did
it in a very last second.
And he is so skilled.
He pressed button just right.
And that gives player a really good feeling of him knowing what he's doing.
But actually again, it's going to be just scripting from us.
So what we need to do here is to make some sort of a timer that would say for how long you can jump
after you left the ground.
And during that time, if you press a jump button, you're still going to jump as if you would jump
from a ground as usually, okay, that's the functionality we're going to make.
If it doesn't make sense right now, just wait a bit.
Let's make it and you'll see what I mean by that.
Let's go to the player script.
And first of all, I would like to do a couple of changes here.
Uh, one of them is I want to rename this variable to activate it.
I think it makes more sense.
Activated.
And second one this boolean can be knocked.
I actually was sure I needed, but it appears that I don't really need it actually.
So we're going to remove it and if we need it in the future, we can always just make it.
And over here.
We need to remove this variable.
And then we can remove this variable from the top as well.
Again because we're not using it.
And then we need to make two variables for Coyote jump because functionality going to be very similar.
And actually this functionality could be used for any things that you need to do with timers or cooldowns.
Let's do end coyote Jump then over here I'm going to make serialized field private float a coyote jump
window.
I'm going to make it 0.5 because I need to be sure it's working.
So I'm putting a bigger value there.
And then private float coyote jump activated.
Very nice.
Now let's go and create a couple of methods so we can use it later on.
First.
When we becoming airborne, we need to sort of activate Coyote Jump when we live in the ground off.
Right.
So for that, we need to make a method that would say something like activate Coyote jump.
I want to have a method even if it has just one line of code, because in that way it is easier to understand
what we're doing there.
So let's make private void.
Activate a coyote jump and it's going to do a very simple thing.
It's going to be coyote jump activated equals to time dot time.
Also, we need a method that would cancel coyote jump once we press the button.
So let's do Private void cancel Coyote Jump and it's going to be coyote jump activated equals to zero.
And this will reset the timer.
And actually I think it's better practice to do time to time minus one.
It's really not that different.
But it kind of makes more sense what we're doing here.
Because y zero you need to like think why there is a zero.
But with the time the time it appears that we just setting it lower than current time so we cannot use
it anymore.
And probably I'll do the same for the buffer.
Jump over here.
Time.
The time minus one, right?
So it will never be bigger than time.
The time after we used the ability.
Very nice.
Now we have these two methods.
It's time to use them.
We should activate Coyote Jump when we live in the ground off.
That happens in the become airborne method.
Over here.
Let's do activate Coyote Jump, but we want to activate it only if we are falling right when we move
it down.
Because otherwise Coyote Jump will be activated every time we jump, and that will make it as a one
additional jump for no reason.
So let's do if rb velocity dot y is less than zero.
Then activate Coyote Jump.
Also, I want to be sure it's working.
So let's add a debug line over here.
Activated Coyote jump.
Let's go ahead and see this debug line in action.
We need to be sure it's working.
So let's go there.
Let's go to play mode.
I'm standing on the ground.
I'm getting off the ground.
Activated coyote jump.
Okay, what if I just jump?
Nothing happens.
And if I go off the ground, there is okay to jump.
Okay.
Very well.
This is what we need.
Let's go back to script.
Let's hide this debug line.
Or actually let's keep it just for now.
So once we activated Coyote Jump, we need to use the coyote jump.
When we attempting to do a regular jump for that we can make a local boolean over here inside of this
method.
And this is how we do it.
It's going to be bool.
Coyote jump available equals two, and it's going to be true only if time.
The time is less than coyote jump activated plus window during which we can use Coyote Jump.
Very nice.
Now let's type here.
We can jump if is grounded or coyote jump activated.
Sorry.
Available.
Coyote jump available?
Yes.
And just to be sure, we're using Coyote Jump.
Let's do this.
If coyote jump available.
Then debug log.
I've used KOAT.
Yeah, my spelling is not entirely correct, but it doesn't really matter.
Now.
Also, once we press the jump button, we should cancel Coyote Jump every time because otherwise it
can be used when it's not supposed to be used.
So after all of the checks with the jump button, let's just type here.
Cancel Coyote Jump and that's it.
We're going to cancel it and it doesn't matter.
It worked.
Or no, if we already jumped then we don't need to jump to be there.
Let's go back to unity now and let me try this.
I'm going to open a full window.
In case you want to see a console.
It is over there.
So I'm going to just jump.
And I've used coyote jump.
Very nice.
So now I can jump off the ledge and it feels like I just did the right timing.
But actually, you know, it was just scripting.
Nice.
I think it's a good ability.
Why not?
Yeah, I think I like it.
Everything is smooth and pretty.
Uh, just once again, I've used code to jump.
Okay.
It's working.
Now you need to play with the value of okay to jump.
What works better for you?
Because half a second is a pretty big value.
I will tell you.
Uh, let me just try.
Dew point two, for example.
Okay.
Yeah.
Still possible.
Yeah, I think it's good, I like it.
Um, maybe.
Point will be there for now and again.
We can rebalance it later on.
All right, coyote jump is ready.
It works very well.
Just before we finish this video, let's go to the rigidbody over here.
And let's change collision detection to continuous.
The difference is very simple collision detection continuous will update collision much more often.
And that is a bit better for our gameplay.
So let's just keep it at continuous okay.
And interpolate interpolate.
Other than that we are good.
Here we're going to discuss body type of rigid body later on.
Don't worry about it.
And we have everything ready to move further.
Yeah, there is still a couple of things we need to do for the player, like his death and respawn,
but we're going to do that when we have level mechanics.
As of now, I think player is ready.
It's a very good foundation.
We have a very fluent feeling from the movement, and now we need some kind of a playground to test
the movement, to see how character feels in the game.
So we're going to go to next video and we're going to make levels there.