WEBVTT

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

00:00.560 --> 00:01.520
Welcome to the video.

00:01.520 --> 00:06.470
So in this one I want to make a buffer jump functionality and to understand it better.

00:06.470 --> 00:09.800
First I want to show you what it does because it's quite confusing actually.

00:09.800 --> 00:11.180
But it is very helpful.

00:11.180 --> 00:15.050
I already made it and I'm going to erase everything and show you how to make it from the start.

00:15.050 --> 00:16.190
But first I want you to see it.

00:16.190 --> 00:17.810
Now look how this works.

00:17.810 --> 00:21.320
I can jump and when I'm falling I can press the jump key.

00:21.320 --> 00:28.280
But if I press the jump key before I land it, this will mean that I pressed the key too early and character

00:28.280 --> 00:30.440
will land on the ground.

00:30.440 --> 00:32.990
He'll lose his velocity and he'll jump again.

00:32.990 --> 00:34.940
Only when we press the jump button again.

00:34.940 --> 00:41.240
But buffer jump allows you to sort of save the input of a space key, and it will bounce off the ground

00:41.240 --> 00:44.510
automatically if you press the button just before you land it.

00:44.510 --> 00:45.920
Something like this will do.

00:46.610 --> 00:49.700
You can see I'm pressing button earlier than I landed.

00:51.080 --> 00:52.820
But I bounced off the ground.

00:53.830 --> 01:01.540
So this one helps to not lose, you know, the velocity and movement and fluent lessness of the movement

01:01.540 --> 01:02.350
of the character.

01:02.350 --> 01:07.630
And also it feels like you are really skilled player and you just press the jump button at the right

01:07.660 --> 01:09.070
time just before you land it.

01:09.070 --> 01:10.600
And that's why you are hopping like that.

01:10.600 --> 01:13.540
But actually it's just a functionality that we made.

01:13.900 --> 01:17.500
You can see how cool it looks and I'm telling you, it feels cool as well.

01:17.500 --> 01:20.890
It feels like I'm doing something right and I just know the character so well.

01:20.890 --> 01:24.520
But actually, it's just, you know, the scripting there helps us do it.

01:24.520 --> 01:30.100
This is how it's going to be if I disable this functionality, you can see how I am not always timing

01:30.100 --> 01:30.940
it, right?

01:32.240 --> 01:37.340
And I'm still a bit running on the ground even I press the button buffer jump allows you to do that.

01:37.340 --> 01:38.630
Hope that I just showed you.

01:38.630 --> 01:39.500
Now let's do it.

01:39.500 --> 01:47.540
So for the buffer jump, we need to know the window during which character still can jump after the

01:47.540 --> 01:48.560
button was pressed.

01:48.560 --> 01:51.890
For that, we need to save the time when button was pressed.

01:51.890 --> 01:58.730
Luckily for us, there is such thing as time dot time, which tells you time in the game and we can

01:58.730 --> 02:04.310
make a variable like a float variable, and then we can save time in the game into that variable.

02:04.310 --> 02:05.720
Let's make a header.

02:06.580 --> 02:08.320
Buffer jump.

02:08.440 --> 02:10.870
And let's make a public for now.

02:10.870 --> 02:11.800
Public float.

02:11.800 --> 02:14.170
Buffer jump pressed.

02:14.350 --> 02:16.510
So when buffer jump was pressed okay.

02:16.810 --> 02:23.620
Now let's go somewhere here I'm going to make a method private void request.

02:25.890 --> 02:32.220
Buffer jump and this method will check if we are in the air is airborne.

02:33.820 --> 02:37.600
Then buffer jump rest equals to time dot time.

02:37.600 --> 02:43.090
If you put your mouse over this time dot time, you can see it says the time at the beginning of the

02:43.090 --> 02:47.320
current frame in seconds since the start of the application.

02:47.320 --> 02:51.880
So basically it's just time in the game and we saving this time to this variable.

02:52.030 --> 02:54.670
Let's go to the space input over here.

02:54.670 --> 02:58.900
And let's request a buffer jump here I'm going to save this.

02:58.900 --> 03:04.150
And we're going to go back to unity and see it in the action okay I'm going to just jump.

03:04.450 --> 03:09.160
And we can see we updating value over here when it was requested.

03:11.120 --> 03:12.170
Here is the value.

03:12.170 --> 03:16.550
So it was requested at 11 seconds of time in the game.

03:17.060 --> 03:20.480
Now we can use this value to activate the buffer jump.

03:20.480 --> 03:23.420
We just need to see if the time that was saved.

03:23.420 --> 03:28.160
Plus the window for the buffer jump is bigger than the current time in the game.

03:28.160 --> 03:32.480
Let's go to the player script and let's make a method.

03:33.190 --> 03:34.330
Private void.

03:35.330 --> 03:36.140
Buffer.

03:37.120 --> 03:38.140
Attempt.

03:39.000 --> 03:41.520
Buffer jump.

03:41.790 --> 03:43.980
Now we need the window.

03:43.980 --> 03:50.070
We need to know for how long we can do the buffer jump, like, during the, uh, couple of seconds

03:50.070 --> 03:51.120
or less than that.

03:51.120 --> 03:52.950
So we're going to do sterilize field.

03:53.780 --> 03:57.170
I'd float buffer, jump window.

03:57.170 --> 04:01.070
And actually I know that good value is point 25.

04:01.070 --> 04:02.570
So I'm going to keep this value.

04:02.570 --> 04:03.980
And this now can be private.

04:03.980 --> 04:05.180
We know what it does.

04:05.180 --> 04:07.760
It's going to have the time when button was pressed.

04:09.490 --> 04:11.020
And now let's go back.

04:11.780 --> 04:12.860
To that method.

04:12.860 --> 04:13.670
Where is it?

04:14.950 --> 04:16.090
Attempt buffer jump.

04:16.090 --> 04:20.440
And here we're going to see if current time in the game is less than time.

04:20.440 --> 04:21.940
When button was pressed.

04:21.940 --> 04:27.040
Plus, the window we created means we still have time to do buffer jump.

04:27.040 --> 04:31.810
And if that's the case, we're going to call jump method and we want to take the buffer jump pressed

04:31.810 --> 04:33.550
and sort of reset it.

04:33.550 --> 04:36.550
We're going to set it to something like zero maybe.

04:36.550 --> 04:40.630
And if we do this then this will not be bigger than time dot time anymore.

04:40.630 --> 04:42.280
And this will work only once.

04:42.280 --> 04:44.020
So it's sort of like a boolean.

04:44.320 --> 04:49.210
Now let's go to the function where we do landing handle landing.

04:49.570 --> 04:53.320
And over here we're going to do attempt buffer jump.

04:53.590 --> 04:57.880
And to make it easier to test I'm going to disable double jump for now okay.

04:58.270 --> 04:59.440
Let's save this.

04:59.440 --> 05:00.520
Let's go back.

05:05.530 --> 05:07.120
Let's go to play mode.

05:08.980 --> 05:10.480
And I'm going to jump.

05:11.230 --> 05:12.910
And I can do the buffer jump.

05:13.770 --> 05:18.810
If you feel like this is too easy to do, you can decrease the value over here to something like 0.1

05:18.810 --> 05:22.950
and it's going to be a bit harder to time the buffer jump, but still possible.

05:24.150 --> 05:25.920
And you can hop like that around.

05:27.150 --> 05:29.280
He doesn't mean you must have this functionality.

05:29.280 --> 05:32.850
It's just one of the ways to improve feeling in the platformer game.

05:33.810 --> 05:34.560
Uh, yeah.

05:34.560 --> 05:36.660
So I'm going to bring back the double jump.

05:40.770 --> 05:41.850
There is this glitch.

05:41.850 --> 05:45.930
When character jumps off the ground right at the start, it is very easy to fix.

05:45.930 --> 05:51.570
We just need to go to the player and make buffer jump activated equals to minus one.

05:51.570 --> 05:52.680
Something like that.

05:54.830 --> 05:57.020
So it will never be true at the start.

05:57.290 --> 06:01.250
Let's make buffer jump window 0.25 and we're good to go.

06:01.280 --> 06:02.540
Thank you for paying attention.

06:02.540 --> 06:04.160
I'll see you in the next video.
