WEBVTT

00:00.050 --> 00:00.500
Hello guys.

00:00.500 --> 00:01.460
Welcome to the video.

00:01.460 --> 00:04.490
In this one I'm going to show you how to make Coyote Jump.

00:04.490 --> 00:07.580
For those who never heard of a coyote jump, let me explain real quick.

00:07.580 --> 00:08.690
So.

00:09.460 --> 00:12.430
Usually character can jump when he's on the ground.

00:12.640 --> 00:19.120
And if player stands, for example, somewhere here, he's still detecting the ground and he can jump.

00:19.120 --> 00:25.270
But if he'll move over here, he won't be detecting the ground and he will not be able to jump, which

00:25.270 --> 00:27.310
is pretty much okay, I think.

00:27.310 --> 00:31.390
But we can improve the feeling of the game by adding a coyote jump.

00:31.390 --> 00:37.720
And this will work basically like a small delay before we take ability to jump from the player, and

00:37.720 --> 00:42.820
with the help of that, he'll be able to jump from this position or maybe even from this position over

00:42.820 --> 00:43.270
here.

00:43.270 --> 00:48.430
And because of that, it's going to feel like he jumped straight off the edge, you know, like he did

00:48.430 --> 00:49.990
it in a very last second.

00:49.990 --> 00:51.070
And he is so skilled.

00:51.070 --> 00:52.480
He pressed button just right.

00:52.480 --> 00:56.350
And that gives player a really good feeling of him knowing what he's doing.

00:56.350 --> 00:58.900
But actually again, it's going to be just scripting from us.

00:58.900 --> 01:04.630
So what we need to do here is to make some sort of a timer that would say for how long you can jump

01:04.630 --> 01:06.130
after you left the ground.

01:06.130 --> 01:10.690
And during that time, if you press a jump button, you're still going to jump as if you would jump

01:10.690 --> 01:14.920
from a ground as usually, okay, that's the functionality we're going to make.

01:14.920 --> 01:17.320
If it doesn't make sense right now, just wait a bit.

01:17.320 --> 01:19.360
Let's make it and you'll see what I mean by that.

01:20.820 --> 01:22.560
Let's go to the player script.

01:22.560 --> 01:25.560
And first of all, I would like to do a couple of changes here.

01:25.800 --> 01:29.520
Uh, one of them is I want to rename this variable to activate it.

01:29.520 --> 01:31.200
I think it makes more sense.

01:32.940 --> 01:33.990
Activated.

01:33.990 --> 01:36.060
And second one this boolean can be knocked.

01:36.060 --> 01:40.770
I actually was sure I needed, but it appears that I don't really need it actually.

01:40.770 --> 01:44.760
So we're going to remove it and if we need it in the future, we can always just make it.

01:45.550 --> 01:46.270
And over here.

01:46.270 --> 01:48.010
We need to remove this variable.

01:49.050 --> 01:52.350
And then we can remove this variable from the top as well.

01:52.350 --> 01:54.000
Again because we're not using it.

01:54.650 --> 02:00.680
And then we need to make two variables for Coyote jump because functionality going to be very similar.

02:00.680 --> 02:05.630
And actually this functionality could be used for any things that you need to do with timers or cooldowns.

02:05.630 --> 02:13.760
Let's do end coyote Jump then over here I'm going to make serialized field private float a coyote jump

02:13.760 --> 02:14.480
window.

02:14.480 --> 02:16.850
I'm going to make it 0.5 because I need to be sure it's working.

02:16.850 --> 02:18.410
So I'm putting a bigger value there.

02:18.410 --> 02:21.680
And then private float coyote jump activated.

02:22.880 --> 02:23.870
Very nice.

02:23.900 --> 02:27.530
Now let's go and create a couple of methods so we can use it later on.

02:28.910 --> 02:29.450
First.

02:29.450 --> 02:35.420
When we becoming airborne, we need to sort of activate Coyote Jump when we live in the ground off.

02:35.420 --> 02:35.810
Right.

02:35.810 --> 02:40.670
So for that, we need to make a method that would say something like activate Coyote jump.

02:41.150 --> 02:46.340
I want to have a method even if it has just one line of code, because in that way it is easier to understand

02:46.340 --> 02:47.300
what we're doing there.

02:47.300 --> 02:49.220
So let's make private void.

02:49.900 --> 02:56.830
Activate a coyote jump and it's going to do a very simple thing.

02:56.830 --> 03:00.610
It's going to be coyote jump activated equals to time dot time.

03:00.610 --> 03:04.420
Also, we need a method that would cancel coyote jump once we press the button.

03:04.420 --> 03:11.800
So let's do Private void cancel Coyote Jump and it's going to be coyote jump activated equals to zero.

03:11.800 --> 03:13.120
And this will reset the timer.

03:13.120 --> 03:18.010
And actually I think it's better practice to do time to time minus one.

03:18.520 --> 03:19.780
It's really not that different.

03:19.780 --> 03:22.570
But it kind of makes more sense what we're doing here.

03:22.570 --> 03:25.870
Because y zero you need to like think why there is a zero.

03:25.870 --> 03:31.060
But with the time the time it appears that we just setting it lower than current time so we cannot use

03:31.060 --> 03:31.870
it anymore.

03:32.350 --> 03:35.230
And probably I'll do the same for the buffer.

03:35.560 --> 03:37.540
Jump over here.

03:38.410 --> 03:38.620
Time.

03:38.620 --> 03:40.660
The time minus one, right?

03:40.660 --> 03:42.400
So it will never be bigger than time.

03:42.400 --> 03:44.830
The time after we used the ability.

03:45.100 --> 03:45.940
Very nice.

03:45.940 --> 03:47.320
Now we have these two methods.

03:47.320 --> 03:48.580
It's time to use them.

03:48.790 --> 03:51.820
We should activate Coyote Jump when we live in the ground off.

03:51.820 --> 03:55.990
That happens in the become airborne method.

03:55.990 --> 03:56.860
Over here.

03:56.860 --> 04:04.480
Let's do activate Coyote Jump, but we want to activate it only if we are falling right when we move

04:04.480 --> 04:04.870
it down.

04:04.870 --> 04:11.620
Because otherwise Coyote Jump will be activated every time we jump, and that will make it as a one

04:11.620 --> 04:13.060
additional jump for no reason.

04:13.060 --> 04:17.020
So let's do if rb velocity dot y is less than zero.

04:17.760 --> 04:19.770
Then activate Coyote Jump.

04:20.130 --> 04:21.600
Also, I want to be sure it's working.

04:21.600 --> 04:23.820
So let's add a debug line over here.

04:24.890 --> 04:27.290
Activated Coyote jump.

04:27.290 --> 04:30.080
Let's go ahead and see this debug line in action.

04:30.080 --> 04:31.340
We need to be sure it's working.

04:31.340 --> 04:32.600
So let's go there.

04:34.660 --> 04:36.850
Let's go to play mode.

04:40.740 --> 04:42.300
I'm standing on the ground.

04:43.990 --> 04:45.610
I'm getting off the ground.

04:45.610 --> 04:47.560
Activated coyote jump.

04:47.560 --> 04:49.540
Okay, what if I just jump?

04:49.540 --> 04:50.920
Nothing happens.

04:52.630 --> 04:55.630
And if I go off the ground, there is okay to jump.

04:55.630 --> 04:56.200
Okay.

04:56.200 --> 04:56.860
Very well.

04:56.860 --> 04:57.850
This is what we need.

04:57.850 --> 04:59.230
Let's go back to script.

04:59.230 --> 05:00.880
Let's hide this debug line.

05:00.880 --> 05:02.950
Or actually let's keep it just for now.

05:03.280 --> 05:06.790
So once we activated Coyote Jump, we need to use the coyote jump.

05:06.790 --> 05:12.550
When we attempting to do a regular jump for that we can make a local boolean over here inside of this

05:12.550 --> 05:13.000
method.

05:13.000 --> 05:14.080
And this is how we do it.

05:14.080 --> 05:15.190
It's going to be bool.

05:16.660 --> 05:23.170
Coyote jump available equals two, and it's going to be true only if time.

05:23.170 --> 05:29.650
The time is less than coyote jump activated plus window during which we can use Coyote Jump.

05:29.650 --> 05:30.670
Very nice.

05:30.670 --> 05:32.290
Now let's type here.

05:32.290 --> 05:37.510
We can jump if is grounded or coyote jump activated.

05:38.320 --> 05:38.680
Sorry.

05:38.680 --> 05:39.490
Available.

05:39.940 --> 05:41.710
Coyote jump available?

05:41.710 --> 05:42.430
Yes.

05:42.430 --> 05:44.650
And just to be sure, we're using Coyote Jump.

05:44.650 --> 05:45.700
Let's do this.

05:45.850 --> 05:47.950
If coyote jump available.

05:48.770 --> 05:49.940
Then debug log.

05:50.360 --> 05:52.940
I've used KOAT.

05:52.940 --> 05:57.470
Yeah, my spelling is not entirely correct, but it doesn't really matter.

05:58.250 --> 05:58.760
Now.

05:58.760 --> 06:04.610
Also, once we press the jump button, we should cancel Coyote Jump every time because otherwise it

06:04.610 --> 06:06.560
can be used when it's not supposed to be used.

06:06.560 --> 06:10.160
So after all of the checks with the jump button, let's just type here.

06:10.160 --> 06:12.590
Cancel Coyote Jump and that's it.

06:12.590 --> 06:15.260
We're going to cancel it and it doesn't matter.

06:15.260 --> 06:15.740
It worked.

06:15.740 --> 06:19.340
Or no, if we already jumped then we don't need to jump to be there.

06:19.490 --> 06:23.630
Let's go back to unity now and let me try this.

06:23.630 --> 06:25.760
I'm going to open a full window.

06:30.550 --> 06:31.990
In case you want to see a console.

06:31.990 --> 06:32.980
It is over there.

06:32.980 --> 06:34.990
So I'm going to just jump.

06:34.990 --> 06:37.000
And I've used coyote jump.

06:41.230 --> 06:42.430
Very nice.

06:42.930 --> 06:47.760
So now I can jump off the ledge and it feels like I just did the right timing.

06:47.760 --> 06:50.490
But actually, you know, it was just scripting.

06:51.210 --> 06:51.720
Nice.

06:51.720 --> 06:53.040
I think it's a good ability.

06:53.040 --> 06:53.820
Why not?

06:58.490 --> 07:00.020
Yeah, I think I like it.

07:02.690 --> 07:05.330
Everything is smooth and pretty.

07:07.690 --> 07:10.630
Uh, just once again, I've used code to jump.

07:10.630 --> 07:10.990
Okay.

07:10.990 --> 07:11.710
It's working.

07:11.710 --> 07:14.050
Now you need to play with the value of okay to jump.

07:14.050 --> 07:15.040
What works better for you?

07:15.040 --> 07:16.990
Because half a second is a pretty big value.

07:16.990 --> 07:17.980
I will tell you.

07:18.340 --> 07:19.510
Uh, let me just try.

07:21.410 --> 07:24.290
Dew point two, for example.

07:25.360 --> 07:26.050
Okay.

07:26.830 --> 07:27.220
Yeah.

07:27.220 --> 07:28.180
Still possible.

07:32.030 --> 07:34.100
Yeah, I think it's good, I like it.

07:34.520 --> 07:35.540
Um, maybe.

07:36.280 --> 07:38.110
Point will be there for now and again.

07:38.110 --> 07:39.850
We can rebalance it later on.

07:39.880 --> 07:41.710
All right, coyote jump is ready.

07:41.710 --> 07:43.270
It works very well.

07:43.270 --> 07:46.990
Just before we finish this video, let's go to the rigidbody over here.

07:46.990 --> 07:50.110
And let's change collision detection to continuous.

07:50.110 --> 07:56.230
The difference is very simple collision detection continuous will update collision much more often.

07:56.230 --> 07:58.870
And that is a bit better for our gameplay.

07:58.870 --> 08:01.030
So let's just keep it at continuous okay.

08:01.270 --> 08:03.220
And interpolate interpolate.

08:03.220 --> 08:04.990
Other than that we are good.

08:05.020 --> 08:07.690
Here we're going to discuss body type of rigid body later on.

08:07.690 --> 08:08.920
Don't worry about it.

08:09.040 --> 08:12.790
And we have everything ready to move further.

08:12.790 --> 08:17.080
Yeah, there is still a couple of things we need to do for the player, like his death and respawn,

08:17.080 --> 08:19.540
but we're going to do that when we have level mechanics.

08:19.780 --> 08:21.760
As of now, I think player is ready.

08:21.760 --> 08:23.290
It's a very good foundation.

08:23.290 --> 08:28.360
We have a very fluent feeling from the movement, and now we need some kind of a playground to test

08:28.360 --> 08:31.330
the movement, to see how character feels in the game.

08:31.330 --> 08:34.600
So we're going to go to next video and we're going to make levels there.
