WEBVTT

00:00.040 --> 00:01.840
Let's make the jumping to do so.

00:01.880 --> 00:03.920
We will open up our player script.

00:04.040 --> 00:06.680
So let's select the player GameObject in the hierarchy.

00:06.840 --> 00:10.200
And let's open up the player script by double clicking on it.

00:10.440 --> 00:14.360
And for that we're going to move over to this update function.

00:14.600 --> 00:17.720
So let's go there and we're going to do it over here.

00:18.080 --> 00:24.640
So what we will do uh we're going to create a variable in order to uh keep track of how many jumps we

00:24.640 --> 00:25.000
want.

00:25.040 --> 00:27.200
Since I want a double jump.

00:27.200 --> 00:30.000
So I'm going to create two variables for it.

00:30.000 --> 00:33.520
So let's go to the top of our class and let's make one.

00:33.640 --> 00:35.560
Uh sorry.

00:35.600 --> 00:38.120
We're going to make a one serialized field.

00:38.280 --> 00:42.240
So this will be serialized field private.

00:42.400 --> 00:45.160
And we're going to call this one this will be float.

00:45.160 --> 00:49.000
Or we can call this uh should be integer as well.

00:49.040 --> 00:52.480
But let's leave it with float variable.

00:52.680 --> 00:55.000
And we're going to call it extra jump.

00:55.000 --> 00:58.800
So let's call it extra jumps jumps.

00:58.800 --> 01:03.450
And let's create one more variable and we're going to make this one private.

01:03.610 --> 01:05.250
Uh, it doesn't need to be public.

01:05.250 --> 01:10.930
So we're just creating two these two variables to just keep track of how many jumps we want.

01:11.170 --> 01:15.290
So we're going to make private, uh, private float.

01:15.290 --> 01:18.010
And we can call this one total jumps.

01:18.050 --> 01:20.210
Total, uh, jumps.

01:20.250 --> 01:22.010
Let's call it total jumps.

01:22.370 --> 01:25.690
And let's close that up with semicolon and extra jump.

01:25.690 --> 01:28.490
By default I'm going to set equal to two f.

01:28.810 --> 01:33.890
Set equal to 2FYI set equal to two f since I want two jumps.

01:33.890 --> 01:34.730
So that's why.

01:35.010 --> 01:37.810
And I'm going to move over to this start function.

01:37.810 --> 01:41.210
So this start function get called in the start of the game.

01:41.210 --> 01:47.970
So in the start of the game what we want to do we're going to set our total jumps equal to our extra

01:47.970 --> 01:48.570
jumps.

01:48.730 --> 01:49.930
Extra jumps.

01:49.930 --> 01:52.170
So this total jumps right over here.

01:52.450 --> 01:54.170
By default it's going to be zero.

01:54.210 --> 02:00.550
But in the start of the game what we're doing we're just setting extra total jumps equal to our extra

02:00.550 --> 02:01.670
jumps, which is two.

02:01.710 --> 02:03.110
As you can notice.

02:03.110 --> 02:07.070
So this total jumps going to be two since this extra jumps is two.

02:07.390 --> 02:08.710
So now what.

02:09.110 --> 02:13.110
So what we're gonna do now we're going to move over to this update function.

02:13.110 --> 02:14.950
And over here we're going to check.

02:15.150 --> 02:17.150
So we're going to make this if condition.

02:17.150 --> 02:19.950
Let's make first bracket and some curly brackets.

02:20.110 --> 02:22.350
And what we want to check over here.

02:22.350 --> 02:28.950
We basically want to check if input if input dot get key down.

02:29.630 --> 02:31.350
And let's make first bracket.

02:31.350 --> 02:33.750
And we're going to pass Keycode key code.

02:33.790 --> 02:36.990
You can pass any key that you want to check with.

02:37.030 --> 02:40.430
So I'm going to pass key code dot space.

02:40.710 --> 02:45.430
My it's basically means if input dot get key down key code dot space.

02:45.430 --> 02:51.910
It basically means that if we press down space key on our keyboard at the same time we're going to check

02:51.950 --> 02:56.950
a, an an a, our total jumps if it's greater than zero.

02:57.360 --> 02:59.200
Basically we have total jumps.

02:59.200 --> 03:02.920
If that is the case, then we're going to make our player jump.

03:03.240 --> 03:07.960
So to make our player jump we can create a function for it.

03:07.960 --> 03:09.640
So let's make it over here.

03:10.000 --> 03:14.800
And that function uh we're going to call it later through a button.

03:14.800 --> 03:20.160
So that's why we're going to mark this function as public void for function.

03:20.160 --> 03:22.640
And we're going to call this function to something like jump.

03:22.640 --> 03:25.640
Let's make first bracket and some curly brackets.

03:25.880 --> 03:27.960
And what we want to do over here.

03:28.120 --> 03:30.760
We basically want to make our player jump.

03:30.760 --> 03:36.800
But before we make we need a reference of this rigid body 2D of this player game object.

03:36.800 --> 03:43.760
Because this rigid body 2D is responsible for velocity, adding force and all of those things.

03:43.760 --> 03:50.120
So that's why we need a reference of this rigid body 2D, uh, so we can make our player jump.

03:50.120 --> 03:54.360
So let's open up our player skip, and let's go to the top of our class.

03:54.360 --> 03:56.320
And let's grab the reference first.

03:57.020 --> 03:58.700
and it doesn't need to be public.

03:58.700 --> 04:00.460
So we're going to make it private.

04:00.620 --> 04:04.260
And the component we're looking for is a rigid body 2D.

04:04.300 --> 04:06.340
And let's call it something like RB.

04:06.500 --> 04:08.780
And let's move over to this start function.

04:08.780 --> 04:14.180
Because in the start of the game we want to grab the reference since we made this field private.

04:14.180 --> 04:18.540
So we're not going to notice underneath our player skip right over here.

04:18.540 --> 04:23.860
So that's why we're gonna do with start function to keep our code a little bit clean.

04:24.180 --> 04:28.060
So what we will do we will use this this dot get component.

04:28.260 --> 04:31.460
And the component we're looking for is a rigid body 2D.

04:31.460 --> 04:35.060
So we're going to pass this rigid body 2D and make this first bracket.

04:35.260 --> 04:41.700
So what we simply doing we just taking our rigid body 2D basically this rigid body 2D of this player

04:41.740 --> 04:42.540
game object.

04:42.540 --> 04:49.540
And now what we're gonna do, we're gonna store this rigid body 2D into this RB field, this rigid body

04:49.540 --> 04:49.940
RB.

04:50.100 --> 04:54.380
So we basically just taking that and now we're going to store it.

04:54.660 --> 04:58.070
So let's store into this RB equal to this.

04:58.070 --> 05:00.750
Basically we're taking this rigid body 2D.

05:00.790 --> 05:05.830
If I move over to unity editor we basically taking this rigid body 2D.

05:05.830 --> 05:08.430
This basically is just referencing itself.

05:08.630 --> 05:13.710
And we're just taking this rigid body 2D component which is dot get component.

05:13.710 --> 05:18.430
And we storing this rigid body 2D into this RB as you can see.

05:18.630 --> 05:21.270
And now we're going to move over to this jump function.

05:21.430 --> 05:27.270
So over here what we're gonna do we're going to create a vector to a vector two.

05:27.310 --> 05:30.390
And we can call this one something like velocity.

05:30.510 --> 05:34.710
And let's set equal to rv dot linear velocity.

05:34.750 --> 05:37.070
We need to set this linear velocity.

05:37.350 --> 05:40.350
So uh before it was something like velocity.

05:40.510 --> 05:45.990
But in unity six we have to type this RB dot linear velocity.

05:46.270 --> 05:49.310
And now what we're going to do we're going to make a uh sorry.

05:49.350 --> 05:51.310
We will uh go to velocity.

05:51.470 --> 05:53.350
And then we're going to access the Y.

05:53.470 --> 05:57.880
And we will set equal to some, uh, some around something like ten F.

05:58.080 --> 06:04.840
And after setting that we're going to set RV dot linear velocity equal to our velocity.

06:04.840 --> 06:06.040
So let me explain.

06:06.320 --> 06:13.080
Firstly we just setting uh this we just created this vector to velocity which gonna have x axis and

06:13.080 --> 06:14.040
y axis.

06:14.040 --> 06:17.920
So we setting equal to rb dot linear velocity.

06:17.960 --> 06:23.160
Basically we just going over to this rigid body 2D of this player uh game object.

06:23.160 --> 06:28.960
And we taking the linear velocity of it and we storing into this vector to velocity.

06:29.160 --> 06:33.200
And after that we basically want to jump in the y axis.

06:33.200 --> 06:37.440
So if I select this move tool we only want to jump in the y axis.

06:37.440 --> 06:40.640
So that's why we just only access the y.

06:40.680 --> 06:43.240
As you can see velocity dot y.

06:43.640 --> 06:48.360
And you can access the x axis as well like velocity dot x.

06:48.520 --> 06:53.900
Since we jump over the uh, since we want our jump in the y axis only.

06:53.900 --> 06:58.700
So that's why we access the velocity dot y and we set equal to ten.

06:58.700 --> 07:05.460
And after that once again we just, uh, going over to this linear velocity of this rigid body 2D of

07:05.460 --> 07:12.220
this player game object, and we say, uh, we just setting equal to velocity after only modifying the

07:12.220 --> 07:15.380
y axis with ten unit, as you can see.

07:15.380 --> 07:18.340
So we're going to jump in the y axis with ten unit.

07:18.460 --> 07:23.340
Firstly we created the variable which is vector to velocity.

07:23.340 --> 07:29.660
And after modifying the y axis we again setting velocity are basically rigid body velocity.

07:29.660 --> 07:35.260
Linear velocity equal to this velocity after modifying the y axis only.

07:35.260 --> 07:39.260
And now what we're going to do we're going to call this jump function over here.

07:39.580 --> 07:45.780
So once we press down space key on our keyboard at the same time total jumps is greater than zero.

07:45.780 --> 07:50.980
And we do know that in the start of the games this total jumps just gonna be two, since we're setting

07:50.980 --> 07:52.270
equal to extra jump, jam.

07:52.310 --> 07:55.630
As you can see and extra jams, by default we set two.

07:55.670 --> 07:57.710
So this one over here is two.

07:57.750 --> 08:00.070
So that's why this total jump is going to be two.

08:00.310 --> 08:02.710
So total jumps will be greater than zero.

08:02.750 --> 08:04.910
Basically means this condition is true.

08:04.910 --> 08:06.910
And also we press down space key.

08:07.070 --> 08:09.110
Then what we want we want jump.

08:09.110 --> 08:11.910
So we're going to call this jump function and jump function.

08:11.910 --> 08:13.670
Just just going to do these things.

08:13.670 --> 08:20.150
It's basically just going to make our player jump in the y axis with ten unit as you can see.

08:20.150 --> 08:22.550
So let's call the jump function over here.

08:22.870 --> 08:24.710
And let's make a first bracket.

08:24.710 --> 08:26.830
And then close that up with semicolon.

08:26.830 --> 08:34.670
And after jumping what we want we want to subtract from this total jumps since we made our jump.

08:34.670 --> 08:36.990
So we can subtract by one unit.

08:36.990 --> 08:41.350
So we will set our total jumps minus equal one.

08:41.710 --> 08:43.270
Basically we just subtracting.

08:43.310 --> 08:45.590
Or you can simply do minus minus.

08:45.590 --> 08:49.110
It's basically means the same thing which is subtracting one.

08:49.110 --> 08:54.810
So if we press down space key on our keyboard at the same time, total jumps is zero.

08:54.810 --> 08:58.130
So if we press done for the first time, then we're going to make jump.

08:58.130 --> 09:00.090
So this total jumps is two.

09:00.210 --> 09:02.450
So two minus one is just going to be one.

09:02.450 --> 09:09.890
And if we press down second time on our keyboard space key then this right over here total jumps is

09:09.890 --> 09:10.330
one.

09:10.330 --> 09:16.610
So which will be still greater than zero or greater than zero means we will be able to jump for the

09:16.610 --> 09:20.610
next time as well since this total jumps is one.

09:20.970 --> 09:24.490
So we jumping and after jumping once again we subtracting.

09:24.490 --> 09:26.570
So one minus one gonna be zero.

09:26.570 --> 09:32.810
And if we press down space key third time and and now this total jumps is zero.

09:32.810 --> 09:34.810
And zero is not greater than zero.

09:34.850 --> 09:37.090
Zero is equals equals to zero.

09:37.130 --> 09:43.330
Basically this condition over here becomes false means we're not going to able to jump since the in

09:43.410 --> 09:46.650
this end condition put this condition should be true.

09:46.690 --> 09:52.860
Else we're not gonna basically we're not gonna able to make our player jump for the third time.

09:53.180 --> 09:59.220
So I hope you get the idea that what we're doing over here, and now we're gonna press down Ctrl s to

09:59.260 --> 10:00.420
save our skip.

10:00.460 --> 10:02.460
And now let's move over to unity.

10:02.660 --> 10:05.220
So we will be able to notice our player.

10:05.220 --> 10:07.940
Just gonna make two jumps two jumps.

10:07.940 --> 10:14.460
And it's not going to make the third jumps because we set our total jumps to extra jumps, which is

10:14.460 --> 10:18.820
by default we set equal to two since we want to jump.

10:18.860 --> 10:23.700
But if you want triple jumps then you can set a extra jumps to three.

10:23.700 --> 10:27.060
So that's why we mark that variable as serialized field.

10:27.060 --> 10:30.220
So we can notice underneath our player skip.

10:30.220 --> 10:31.860
So just wait a little moment.

10:31.860 --> 10:36.540
Once it's compiled we can see uh, we can notice underneath our player skip.

10:36.580 --> 10:43.140
As you can see, as soon as our player skip gets compiled extra jumps big as by default we set two.

10:43.300 --> 10:49.640
And now if we click on this play button in the top in order to play our game and press down space key

10:49.680 --> 10:50.920
on our keyboard.

10:50.920 --> 10:57.680
You will see our player just jump in the Y axis with ten units, as we said, and we're just gonna able

10:57.680 --> 10:58.680
to jump two times.

10:58.680 --> 11:01.600
So if I press run first, then second, as you can see.

11:01.880 --> 11:08.520
But if I try to press down space key on my keyboard, it's not jumping at all.

11:08.520 --> 11:08.920
Why?

11:09.080 --> 11:15.200
Because if we move over to unity, uh, sorry, uh, code, uh, this total jumps became zero.

11:15.240 --> 11:19.000
We just loses all of our jumps after jumping.

11:19.000 --> 11:21.280
We just subtracting, as you can see.

11:21.280 --> 11:24.480
So this total jumps is now something like zero.

11:24.480 --> 11:31.360
So once it is zero then we're gonna set back again to our total jumps to extra jump.

11:31.360 --> 11:34.960
So we can able to jump for the next time as well.

11:35.280 --> 11:40.200
So what we need to do we're going to create a variable, uh, something like scrum.

11:40.200 --> 11:46.840
And that will be a bool variable to just keep track of if this player is standing on this ground or

11:46.840 --> 11:47.360
not.

11:47.360 --> 11:48.850
So we're gonna to do that.

11:48.850 --> 11:55.050
So if it's standing on this ground then we're going to set our uh this total jumps to our extra jumps

11:55.050 --> 11:55.890
one more time.

11:55.890 --> 11:57.810
So this condition just going to be true.

11:57.810 --> 12:02.770
So we are just going to make, uh, our player jump, uh, one more time.

12:02.930 --> 12:05.130
One more time, basically two times.

12:05.170 --> 12:09.410
Uh, we can able to jump once we are standing on that ground.

12:09.410 --> 12:11.570
So we're going to create a variable for it.

12:11.570 --> 12:15.490
So let's get out of play mode and let's move over to our script.

12:15.770 --> 12:18.730
And for that we will go to top of our class.

12:18.730 --> 12:20.370
And it doesn't need to be public.

12:20.370 --> 12:22.770
So we can simply make it private.

12:22.770 --> 12:27.530
So this will be private and that will be pool which can be true or false.

12:27.770 --> 12:33.810
And uh, this variable just going to keep track of if we are standing on that ground or not.

12:33.810 --> 12:37.890
So we can say we're going to say something like is ground.

12:38.090 --> 12:41.050
And uh, and let's close that up with semicolon.

12:41.050 --> 12:47.980
So basically what we want to do, we basically want to uh, create a, we will create a point somewhere

12:47.980 --> 12:48.940
around here.

12:48.940 --> 12:51.780
And from that point we're going to create a circle.

12:51.780 --> 12:58.180
And if that circle collide with this ground, then we're going to set our total jumps to our extra jump.

12:58.220 --> 13:03.380
Basically, we just want our player to jump if that circle collides with this ground.

13:03.780 --> 13:05.420
So we're going to create the circle.

13:05.420 --> 13:07.500
So let's create an tile game object.

13:07.500 --> 13:10.700
And from that point we will create our circle.

13:10.700 --> 13:15.500
And if that circle collides with this ground then we're going to make our player jump.

13:15.500 --> 13:19.420
Else we not gonna make it because the player will be in the air.

13:19.420 --> 13:20.260
So that's why.

13:20.660 --> 13:22.140
So let's create a point.

13:22.140 --> 13:25.540
So we will select our player GameObject in the hierarchy.

13:25.580 --> 13:26.820
Let's right click on it.

13:26.820 --> 13:29.300
And let's create an empty game object.

13:29.300 --> 13:32.900
And we will call this GameObject to something like Round Check.

13:33.060 --> 13:34.940
So let's call it Ground Check.

13:35.340 --> 13:37.660
And let's select the move tool from here.

13:37.660 --> 13:41.140
And let's move it in the bottom somewhere around here.

13:42.220 --> 13:44.700
And we're going to choose an gizmos for it.

13:44.700 --> 13:47.000
So let's choose this one.

13:47.600 --> 13:49.680
And this seems fine.

13:50.240 --> 13:53.640
And so from this point we want to create the circle.

13:53.640 --> 13:59.760
So let's open up our script and we're going to do it over here inside this update function.

13:59.760 --> 14:01.360
So let's do it here.

14:01.720 --> 14:04.480
Let's do it before this if condition.

14:04.960 --> 14:13.600
So what we're going to do to create circle we need to use this physics 2D physics 2D dot overlap circle

14:13.840 --> 14:20.560
overlap circle sorry physics 2D overlap circle.

14:20.800 --> 14:26.720
And this function over here as a first argument, it's going to take the point from where we want to

14:26.720 --> 14:28.760
create the circle or the position.

14:28.760 --> 14:31.760
So we're going to create the circle from this ground check point.

14:32.120 --> 14:34.920
And the second thing it's going to take the radius.

14:34.960 --> 14:40.480
And the third argument it's going to take the layer mask basically which game object we want to target

14:40.480 --> 14:42.400
since we want to target this ground.

14:42.400 --> 14:45.810
So we need to assign this ground as a ground layer.

14:45.810 --> 14:52.330
But before we do so, let's make this comment and comment and don't interrupt our quotes.

14:52.330 --> 14:59.730
So basically just type, uh, just uh, type two forward slashes and let's go to top of our class because

14:59.730 --> 15:02.730
we need to, uh, grab those, uh, things.

15:02.730 --> 15:05.930
So first thing, what we need, uh, we need a point.

15:05.930 --> 15:08.690
So let's make a serialize field private.

15:08.970 --> 15:15.490
And for point or position, we're going to type transform, which is responsible for position or point.

15:15.970 --> 15:23.450
And uh, and we can call this one ground check ground check point, something like that.

15:23.650 --> 15:25.930
And the second thing we need the radius.

15:25.930 --> 15:30.970
So let's make a another class field private, uh, float.

15:30.970 --> 15:35.250
And we can call this one check radius radius.

15:35.250 --> 15:38.690
And by default I'm going to set something like point two.

15:39.050 --> 15:44.950
Uh, if a smaller number and the third argument, it's going to take the layer mask or which game object

15:44.950 --> 15:46.150
we want to target.

15:46.150 --> 15:48.990
So in our case we're gonna target this crown.

15:49.750 --> 15:52.990
So as a layer mask we're gonna choose that crown.

15:52.990 --> 15:58.790
But before we do let's assign so serialize fill private layer mask.

15:58.990 --> 16:07.110
And we're going to call this one target layer or let's call it what is Crown as simply what is Crown.

16:07.590 --> 16:09.670
And let's close that up with semicolon.

16:09.670 --> 16:12.270
Let's press down Ctrl S to save our script.

16:12.270 --> 16:14.190
And now let's move over to unity.

16:14.710 --> 16:17.590
So now let's hope it's gonna work.

16:17.630 --> 16:22.710
Basically underneath our player skip we will able to notice those variables.

16:22.710 --> 16:26.150
So the first thing will be our crown check point.

16:26.150 --> 16:28.390
So we need to select our crown check.

16:28.390 --> 16:30.710
And we need to drag it in that slot.

16:30.710 --> 16:32.550
So we will have the point.

16:32.590 --> 16:37.190
So as you can see as soon as our player skip compiles crown check point.

16:37.190 --> 16:39.990
And it says none transform basically empty.

16:40.030 --> 16:43.480
So we're going to take our crown check underneath our player game object.

16:43.480 --> 16:46.040
Let's drag it there and check radius.

16:46.040 --> 16:48.280
By default we just given 0.2.

16:48.320 --> 16:53.560
You can just go with any number that you like, but make sure you go with smaller.

16:53.560 --> 16:54.520
And what is ground?

16:54.520 --> 16:59.840
We're gonna choose our ground, but before we choose our ground, we need to assign this ground as a

16:59.840 --> 17:00.840
ground layer.

17:00.840 --> 17:02.280
So how we can do that?

17:02.280 --> 17:06.120
Firstly, we need to select our GameObject in the hierarchy first.

17:06.120 --> 17:07.640
Then go over to Inspector.

17:07.640 --> 17:10.760
In the top right you can see layer and it says default.

17:10.760 --> 17:13.520
So just click there and then click on Add Layer.

17:13.800 --> 17:15.640
And we're gonna add a new layer.

17:15.840 --> 17:18.200
And you can name the layer whatever you want.

17:18.240 --> 17:20.480
So I'm going to call it ground.

17:20.640 --> 17:22.160
So let's call it ground.

17:22.280 --> 17:25.640
And let's select our player script one more time.

17:25.640 --> 17:26.760
And what is ground.

17:26.760 --> 17:27.720
As you can see.

17:27.760 --> 17:28.360
Sorry.

17:28.400 --> 17:29.840
We're gonna choose our ground.

17:29.840 --> 17:32.880
And we need to assign this ground as a ground layer.

17:32.880 --> 17:34.280
So we already created.

17:34.280 --> 17:37.920
So we're going to choose our GameObject one more time in the hierarchy.

17:38.080 --> 17:39.640
Then go over to Inspector.

17:39.680 --> 17:41.720
As you can see layers is default.

17:41.770 --> 17:43.130
so we will choose ground.

17:43.170 --> 17:46.250
Now we assign it this ground as a ground layer.

17:46.290 --> 17:48.370
Now we will select our player skip.

17:48.370 --> 17:49.450
And what is ground.

17:49.450 --> 17:50.970
We're going to choose our ground.

17:51.010 --> 17:54.250
Now the circle only going to check for with this ground.

17:54.530 --> 17:57.810
And we just assign it all of the variables.

17:57.810 --> 17:59.970
And we are ready to create that.

17:59.970 --> 18:03.290
So let's open up our player script by double clicking on it.

18:03.930 --> 18:06.210
And let's remove these two slashes.

18:06.370 --> 18:08.170
And let's use this function.

18:08.170 --> 18:10.410
So this overlap as a first argument.

18:10.410 --> 18:13.970
It's going to take the point from where we want to create the circle.

18:13.970 --> 18:20.090
So we're going to pass our ground checkpoint dot position and ground checkpoint dot position.

18:20.130 --> 18:21.610
We do know that ground check.

18:21.650 --> 18:25.050
We just pass our ground checkpoint as you seen.

18:25.290 --> 18:27.490
And the second thing it's going to take the radius.

18:27.490 --> 18:29.890
So we will pass our check radius.

18:29.890 --> 18:32.450
And the third argument it's going to take the layer mask.

18:32.450 --> 18:36.130
So we will pass our what is ground and what is ground.

18:36.130 --> 18:38.010
We have chosen our ground.

18:38.010 --> 18:40.130
And let's close that up with semicolon.

18:40.130 --> 18:45.830
So this function right over here, it's gonna create the circle around this ground check point with

18:45.830 --> 18:49.470
this much of radius and just going to target our ground.

18:49.470 --> 18:52.990
So it's gonna create a somewhere around here.

18:53.230 --> 18:58.510
And if that circle really collide with this ground, then this function over here, it's going to give

18:58.550 --> 18:59.430
a true value.

18:59.470 --> 19:01.830
Else it's going to give a false value.

19:01.830 --> 19:06.550
So what we will do we're going to store that result into this ground parameter.

19:06.550 --> 19:12.750
Basically we created this parameter to just keep track of if this player is standing on this ground

19:12.750 --> 19:13.270
or not.

19:13.310 --> 19:17.510
If it's uh, then uh, then we want we gonna make jump.

19:17.510 --> 19:23.710
So what we will do, we will set our is crown is crown equal to this.

19:23.950 --> 19:31.190
So this, uh, basically this physics 2D dot overlap circle can be true or false depending upon if the

19:31.190 --> 19:34.150
circle is really colliding with this crown or not.

19:34.190 --> 19:36.670
Let's suppose the circle collide with this ground.

19:36.670 --> 19:39.310
So this function over here, it's gonna be true.

19:39.310 --> 19:43.160
So And which setting is ground equal to this as you can see.

19:43.160 --> 19:47.200
So that's why this is ground going to be true and is ground going to be true.

19:47.200 --> 19:52.240
And let's suppose the circle don't collide with this round.

19:52.400 --> 19:56.840
And then this function over here it's going to give us a false value.

19:56.840 --> 19:59.520
So that's why this is ground right over here.

19:59.520 --> 20:00.760
It's going to be false.

20:01.120 --> 20:02.280
It's going to be false.

20:02.680 --> 20:03.880
So what we will do.

20:04.040 --> 20:10.280
And we created this parameter to just keep track of in in order to standing on this ground or not.

20:10.600 --> 20:15.920
And if this ground is true basically means this player is standing on this ground.

20:15.920 --> 20:19.480
So what we need to do, we need to set our extra jumps.

20:19.600 --> 20:22.520
Sorry, total jumps to our extra jumps.

20:22.760 --> 20:24.880
Uh, since we are standing on this ground.

20:24.880 --> 20:25.840
So that's why.

20:26.200 --> 20:31.080
So what we're gonna do now, we're going to check, uh, so we will use this if condition.

20:31.080 --> 20:36.160
Let's make first bracket and some curly brackets and what we want to check over here, we're going to

20:36.160 --> 20:43.620
check if is ground is equals Equals to true basically means that that player is standing on this ground

20:43.620 --> 20:46.580
or the circle really colliding with this ground.

20:46.580 --> 20:53.220
So what we need to do now, we basically need to set our, uh, total jumps to our extra jumps.

20:53.220 --> 20:58.900
And we do know once we're going to set back, uh, so we will able to jump, uh, for the next time

20:58.900 --> 21:05.340
as well, we can make double jump for the next time, or you can just leave it like this, uh, is ground.

21:05.340 --> 21:09.140
It's also basically means true means we are standing on this ground.

21:09.140 --> 21:14.540
So now what we're going to do, we're going to set our total jumps equal to our extra jumps.

21:14.820 --> 21:17.020
And let's close that up with semicolon.

21:17.140 --> 21:20.540
And now we're going to press down Ctrl S to save our script.

21:20.540 --> 21:22.500
And now let's move over to unity.

21:22.780 --> 21:29.380
And we will able to notice as soon as this player just gonna stand on this ground or the circle collide

21:29.380 --> 21:34.780
with this, uh, ground, then we just setting extra total jumps to our extra jumps.

21:34.780 --> 21:38.030
Basically, we simply just making jump.

21:38.870 --> 21:44.350
Uh, we just created that parameter to just keep track of if we're standing on this ground or not.

21:44.550 --> 21:51.790
Uh, but it would be nice if we able to see our circle, uh, to the C circle or to draw the circle,

21:51.790 --> 21:55.230
we need to use another inbuilt function of unity.

21:55.430 --> 21:57.190
So let's open up our player.

21:57.190 --> 22:00.270
Skip one more time and let's do it in the bottom.

22:00.270 --> 22:02.350
You can do it anywhere you want.

22:02.590 --> 22:06.750
And make sure you just do as I as I have done over here.

22:06.870 --> 22:10.270
It's a void Ondraw Cosmo selected function.

22:10.270 --> 22:15.590
So this function gets called when, uh, sorry, it's called by unity itself.

22:15.750 --> 22:19.230
And this function just gonna draw whatever you want to draw.

22:19.390 --> 22:22.630
So what we're going to do, we're going to draw the circle.

22:22.630 --> 22:30.230
So that's why we're going to use this gizmos dot draw where sphere function and this function just gonna

22:30.270 --> 22:31.230
draw the circle.

22:31.430 --> 22:35.950
So first thing it's going to take the point from where we want to create the circle.

22:35.950 --> 22:39.080
So we will pass our ground checkpoint position.

22:39.080 --> 22:39.720
From there.

22:39.720 --> 22:41.520
We want to create the circle.

22:41.520 --> 22:44.200
And the second thing it's going to take the radius.

22:44.200 --> 22:46.640
So we will pass our check radius.

22:46.640 --> 22:48.840
And let's close that up with semicolon.

22:48.840 --> 22:51.640
But before we draw the circle we need to check.

22:51.680 --> 22:56.600
Let's suppose if you haven't dragged this ground check to this ground check field basically means this

22:56.600 --> 22:59.360
ground check point is empty means none.

23:00.040 --> 23:04.600
So over here, as you can see, we still are using this function.

23:04.600 --> 23:07.000
And we're just trying to finding that position.

23:07.000 --> 23:09.880
And we're drawing the circle with this much of radius.

23:09.880 --> 23:15.040
And if you haven't assigned so this function not going to able to find this ground check point.

23:15.040 --> 23:17.800
So that's why it's gonna throw us an error.

23:17.800 --> 23:23.680
So before we draw the circle we need to check if we assign it our ground check point or not.

23:23.680 --> 23:31.240
So that's why before we draw, we will check if our ground checkpoint, if it's not equal to null,

23:31.760 --> 23:32.960
not equal to null.

23:32.960 --> 23:35.000
Let's make this a curly brackets.

23:35.000 --> 23:36.580
Then we're going to draw the circle.

23:36.580 --> 23:42.620
So we're gonna cut this by control X and we're going to paste it inside the control V.

23:42.820 --> 23:49.260
So what we simply have done over here, we basically checking if our ground check point is not equal

23:49.260 --> 23:54.020
to null basically means that we just drag this ground check to this ground check.

23:54.020 --> 23:56.060
And this field is not empty.

23:56.100 --> 24:00.260
Then what we're doing then we're just drawing the circle, as you can see.

24:00.260 --> 24:04.100
So before you draw the circle make sure you assign it.

24:04.100 --> 24:06.660
So that's why we're using this if condition.

24:06.900 --> 24:11.060
And if you want to choose another color you want to draw with.

24:11.060 --> 24:13.540
So before you draw you can select the color.

24:13.540 --> 24:19.380
And in order to select the color you can use this gizmos dot color equal to color that you like.

24:19.380 --> 24:21.940
So I'm going to set color dot yellow.

24:22.220 --> 24:24.420
And let's close that up with semicolon.

24:24.420 --> 24:27.740
And now we're going to press down Ctrl S to save our script.

24:27.740 --> 24:31.660
And this function automatically gonna call by unity itself.

24:31.860 --> 24:36.070
And it's going to draw the circle Uh, from our from checkpoint.

24:36.710 --> 24:43.470
And now we're going to able to notice that circle, and we can play around with our, uh, check radius,

24:43.510 --> 24:46.990
uh, in order to adjust the radius of that circle.

24:47.270 --> 24:48.870
So just wait a little moment.

24:48.870 --> 24:56.790
As you can see, as soon as our script compiles, we can notice, uh, our, uh, circle from this ground

24:56.790 --> 24:57.470
check point.

24:57.470 --> 25:04.750
And we can make this a little bit small by playing around with or just messing with this check radius.

25:04.750 --> 25:09.790
We can make it even more smaller, but I'm going to leave with 0.2.

25:10.390 --> 25:12.390
Basically, choose a smaller number.

25:12.830 --> 25:16.390
And now we should able to see.

25:16.670 --> 25:23.670
So if I just press uh click play button in the top you will see uh, sorry.

25:24.630 --> 25:30.550
Uh, you will see that as soon as we're gonna collide with this, uh, ground or just gonna stand on

25:30.550 --> 25:33.650
this ground, we will able to notice this player will jump.

25:33.690 --> 25:36.330
Else it's not gonna make jump at all.

25:36.330 --> 25:37.770
So if I press down space key.

25:37.810 --> 25:44.770
As you can see, we only able to make jump once the circle is colliding with this ground and we only

25:44.770 --> 25:47.170
just are making two jumps.

25:47.170 --> 25:49.690
As you can see, not more than that.

25:49.810 --> 25:52.490
One, two and not more than that.

25:52.490 --> 25:58.210
But as soon as this player just colliding with this ground or this circle collide with this ground,

25:58.250 --> 26:04.530
we able to make jump because we just setting this total jumps to our extra jumps, which is two.

26:04.810 --> 26:08.010
And let's suppose you set it to one extra jumps.

26:08.010 --> 26:12.530
So if I set to one we just gonna only able to make one jump.

26:12.530 --> 26:15.970
As you can see we not making more than that.

26:16.210 --> 26:16.690
Sorry.

26:16.730 --> 26:20.130
We sometimes making because the circle is too much big.

26:20.410 --> 26:22.770
And let's suppose we want to make three jumps.

26:22.770 --> 26:30.370
So if we put our extra jumps to three so we can make three jumps as you one two, three as you can see.

26:30.730 --> 26:38.100
So I hope you get the idea that how you can make the jump, and it would be nice if we are able to notice

26:38.460 --> 26:45.540
or adjust our jump height in underneath our player skip, and we don't need to go to that skip and change

26:45.540 --> 26:51.140
the, uh, change the jump height, uh, or basically that thing.

26:51.140 --> 26:54.980
So we're going to get out of play mode and we will open up our player skip.

26:54.980 --> 27:01.900
And instead of setting directly or hard coding this like over here, as you can see, velocity dot y

27:02.060 --> 27:04.220
we just set equal to ten f.

27:04.260 --> 27:10.700
Instead of doing that, let's make a variable to uh, and we can just gonna make that public or say

27:10.700 --> 27:14.220
less fill so we can adjust underneath our player skip.

27:14.220 --> 27:20.380
So we don't need to come to the script and change this value over again and again to match up the correct

27:20.420 --> 27:21.140
jump height.

27:21.180 --> 27:28.780
So we will go to top of our class and let's make another serialized field, serialized field a private.

27:28.780 --> 27:30.980
And we're going to call this one something.

27:31.200 --> 27:32.360
This will be float.

27:32.360 --> 27:34.640
And let's call this one jump height.

27:34.680 --> 27:36.520
So let's call it jump height.

27:36.520 --> 27:39.120
And by default I'm going to set equal to 12.

27:39.560 --> 27:41.640
And let's close that up with semicolon.

27:41.640 --> 27:45.320
And now we're going to replace this with our jump height.

27:45.320 --> 27:47.960
So let's pass our jump height sorry.

27:48.440 --> 27:53.240
Jump height and jump height by default set with 12.

27:53.240 --> 27:57.280
So we will able to jump in the y axis with 12 unit.

27:58.400 --> 28:02.120
And now we're going to press down Ctrl S to save our skip.

28:02.120 --> 28:04.320
And now let's move over to unity.

28:04.680 --> 28:11.000
So in the Y we will able to make jump with a jump height parameter.

28:11.200 --> 28:13.320
And by default we set it to 12.

28:13.360 --> 28:15.680
But we just made it a serialized field.

28:15.680 --> 28:19.920
So we can notice underneath our player skip right over here.

28:20.200 --> 28:25.760
So as you can notice right over here jump height which is by default we set 12.

28:25.760 --> 28:29.160
So I'm going to make it a little bit bigger something like 15.

28:29.360 --> 28:33.570
And I want to decrease the radius of this circle.

28:33.730 --> 28:39.610
So I'm going to go with something like .1.15 something like that.

28:39.770 --> 28:41.770
And now this seems perfect.

28:42.090 --> 28:43.810
And also extra jumps.

28:43.850 --> 28:46.730
I want to so I'm going to leave it extra jumps to two.

28:47.170 --> 28:48.690
And let's go to overrides.

28:48.690 --> 28:51.170
And then make sure you click on this apply all.

28:51.170 --> 28:54.970
If you turn it your player game object into a prefab.

28:55.290 --> 28:59.330
And if we just go ahead and then click on this play button in the top.

28:59.490 --> 29:01.410
By now it would be fine.

29:01.450 --> 29:02.810
It's just gonna be fine.

29:02.930 --> 29:09.370
So whenever we're touching our ground or this player just touching our ground, then we're just setting

29:09.370 --> 29:11.490
our total jumps to extra jumps.

29:11.530 --> 29:12.610
As you can see.

29:12.610 --> 29:14.250
So we're making too much.

29:14.250 --> 29:16.210
So I'm going to make jump height to ten.

29:16.570 --> 29:19.330
And we're making so as you can see.

29:19.330 --> 29:20.970
So this seems pretty much cool.

29:20.970 --> 29:22.650
So I hope you get the idea.

29:22.690 --> 29:24.370
And let me explain one more time.

29:24.370 --> 29:26.050
So I'm gonna get out of play mode.

29:26.050 --> 29:28.170
So if I move over to my script.

29:28.170 --> 29:34.740
So so this function over here, just creating that circle from that ground check point with this much

29:34.740 --> 29:37.100
of radius and targeting our ground.

29:37.100 --> 29:38.980
So this can be true or false.

29:39.140 --> 29:44.420
And if the circle is really colliding with this ground, then this over here gonna be true.

29:44.580 --> 29:47.900
And that's why this is ground, uh, just gonna be true.

29:47.900 --> 29:53.380
And we created this variable to just keep track of if we're standing on this ground or not.

29:53.540 --> 29:58.780
And if it's then what we're doing if this ground is true, basically means that circle is colliding

29:58.780 --> 30:04.140
with that ground, then we're setting total jumps to our extra jumps and to extra jumps.

30:04.140 --> 30:05.860
By default we set two.

30:05.900 --> 30:08.300
So this total jumps gonna be two.

30:08.500 --> 30:15.420
And so this an end condition basically this condition getting true once again because total jump is

30:15.540 --> 30:18.860
uh is true once our s ground parameter is true.

30:18.860 --> 30:20.820
Basically standing on that ground.

30:20.820 --> 30:23.460
And we do know that two is greater than zero.

30:23.700 --> 30:25.500
So that's why we're making jump.

30:25.500 --> 30:31.160
And after jumping we just subtracting from their total jumps one unit, as you can see.

30:31.160 --> 30:34.320
So it's going to be one and once it's one.

30:34.320 --> 30:39.360
And if we press down space key on our keyboard and total jumps is greater than zero.

30:39.800 --> 30:41.640
So this total jumps is one.

30:41.640 --> 30:43.280
So one is greater than zero.

30:43.480 --> 30:46.560
So the condition the condition is still true.

30:46.680 --> 30:48.360
So that's why we jumping.

30:48.400 --> 30:50.360
And once again we subtracting.

30:50.360 --> 30:52.600
So one minus one is just going to be zero.

30:52.600 --> 30:56.840
And now if we jump this total jumps is zero.

30:56.840 --> 30:59.200
And zero is not greater than zero.

30:59.200 --> 31:05.080
So that's why we are not able to jump for the third time or that we're making a jumping.

31:05.080 --> 31:11.640
But as soon as we colliding with this ground, as you can see, we setting total jumps equal to our

31:11.680 --> 31:13.320
extra jumps, which is two.

31:13.360 --> 31:16.000
So this total jumps becomes one more time to.

31:16.120 --> 31:21.800
So this end condition right over here becomes one more time to true to true.

31:21.800 --> 31:24.840
So that's why we able to make our player jump.

31:25.000 --> 31:31.010
So I hope you get the idea that how you can make jam and you can make jam as many times as you want,

31:31.210 --> 31:38.330
and it would be nice if we just give it a title somewhere over here, uh, underneath our player, skip

31:38.490 --> 31:39.890
over here a title.

31:40.010 --> 31:43.450
And in order to give a title, we need to use header.

31:43.450 --> 31:45.610
So we will open up our player skip.

31:45.810 --> 31:48.170
And we will go to top of our class.

31:48.410 --> 31:56.450
And over here, uh, so this right over here I'm going to put this line of code, this one uh, by hold

31:56.490 --> 31:57.850
down alt on your keyboard.

31:57.850 --> 32:02.810
And you can use up and down arrow in order to move your, uh, line of code.

32:03.010 --> 32:07.250
And so this, uh, all of these things right over here is jumping.

32:07.570 --> 32:10.290
Uh, so that's why I'm gonna give a title.

32:10.330 --> 32:15.810
To give a title, we need to make this square brackets, and we need to type this header, and we need

32:15.810 --> 32:17.130
to make this brackets.

32:17.130 --> 32:22.370
And inside this bracket in quotation, you can just give the title that you want.

32:22.410 --> 32:30.510
So so since this this all of this variable is for jumping, so I'm going to call it player jump section.

32:30.510 --> 32:33.190
Or simply we can call it jump as well.

32:33.310 --> 32:40.350
And now if we press down space sorry Ctrl s on our keyboard in order to save our skip and then move

32:40.350 --> 32:48.350
over to unity underneath our player skip, we will notice a title, a title, something says player

32:48.350 --> 32:50.270
jump as we have given.

32:50.270 --> 32:50.710
So.

32:50.950 --> 32:53.910
So you need to use a square brackets then header.

32:53.910 --> 32:59.030
And inside that brackets you basically need to put quotation and then the title.

32:59.030 --> 33:03.630
As you can see underneath our player skip we can say player jump title.

33:03.630 --> 33:08.990
And underneath we can see all of the things variables for our jumping.

33:09.350 --> 33:11.670
And we can it's just make it cool.

33:11.670 --> 33:12.550
So that's why.

33:12.830 --> 33:18.550
And we will go to overrides and then apply all if it's we change something around with this player game

33:18.590 --> 33:19.110
object.

33:19.110 --> 33:20.550
So it's gonna be save.

33:20.550 --> 33:25.670
And now I'm gonna press Ctrl s on my keyboard in order to save my project.
