WEBVTT

00:00.080 --> 00:05.840
Once we making our player game object jump at the same time, we need to play the jump animation clip.

00:05.840 --> 00:07.440
We're not playing at all.

00:07.440 --> 00:08.480
So let me show you.

00:08.480 --> 00:14.000
Let's click on this play button in the top to play our game, and let's have a look on it.

00:14.440 --> 00:19.640
So once we just making our player jump it's the jump animation.

00:19.640 --> 00:20.520
It's not playing.

00:20.520 --> 00:24.720
We just playing the run animation clip over again and again.

00:24.720 --> 00:30.760
So if I press down space key on my keyboard, as you can see we just still playing the running animation

00:30.760 --> 00:31.120
clip.

00:31.160 --> 00:37.040
Even we are in the air, so we need to play the jump animation clip instead of the running.

00:37.040 --> 00:38.640
So let's get out of play mode.

00:38.640 --> 00:43.480
And if we select our player GameObject in the hierarchy, then move over to animator tab.

00:43.640 --> 00:50.760
As you can see in previous chapter in animator, once we created those animation, or you can simply

00:50.760 --> 00:55.280
say in Animation Transition chapter, we just said this jump parameter.

00:55.280 --> 00:59.760
So this jump which is a bool parameter which can be true or false.

00:59.760 --> 01:03.570
So what we basically need we need to set this jump parameter to true.

01:03.570 --> 01:08.770
And we do know once we set this jump parameter to true, it's going to play the jump animation clip

01:08.770 --> 01:09.690
right away.

01:09.970 --> 01:15.450
So what we need if we select our player game object and then move over to Inspector, we can see an

01:15.490 --> 01:20.410
animator component is attached to this player once we created those animation clip.

01:20.450 --> 01:24.410
Basically this running as well as the jumping animation clip.

01:24.410 --> 01:29.490
So once we created those animation clip, this animator component just added right away.

01:29.490 --> 01:33.410
So what we need, we need a reference of this animator component.

01:33.410 --> 01:40.010
And then we can set this jump parameter to true or False depending upon what player is really doing.

01:40.450 --> 01:41.650
We need to do that.

01:42.250 --> 01:44.450
So we do know we need a reference.

01:44.450 --> 01:46.410
Then we can set this parameter.

01:46.410 --> 01:48.210
So let's grab the reference first.

01:48.210 --> 01:50.130
So we're going to open up our player script.

01:50.130 --> 01:52.730
So let's select the player GameObject in the hierarchy.

01:52.730 --> 01:56.690
And let's open up the player script by double clicking on it in the inspector.

01:56.690 --> 01:58.290
So we need a reference.

01:58.290 --> 02:02.650
So let's go to the top of our class so you can make it anywhere you like.

02:02.770 --> 02:05.770
So I'm gonna make it underneath this rigid body feel.

02:06.210 --> 02:11.530
And we're going to make it public because we're going to set this underneath our player script, right

02:11.530 --> 02:15.210
underneath our player, somewhere over here in the Inspector.

02:15.530 --> 02:18.250
And the component we're looking for is a animator.

02:18.250 --> 02:21.770
So we need to type this animator, the component we're looking for.

02:21.810 --> 02:25.370
And we also have to name the reference what we want to name it.

02:25.370 --> 02:30.090
So I'm going to call it something like animator with Non-capitalized a letter.

02:30.210 --> 02:32.370
And let's close that up with semicolon.

02:32.370 --> 02:35.810
And let's press down control S in order to save our script.

02:35.810 --> 02:38.250
And let's move over to unity.

02:38.450 --> 02:39.930
So we need a ref.

02:40.250 --> 02:43.490
We basically need to grab the reference first.

02:43.730 --> 02:48.570
So underneath our player script we're going to able to see another field just going to appear.

02:48.570 --> 02:50.370
And it will be animator.

02:50.690 --> 02:56.930
So as soon as the player script gets compiled we can see underneath our player script an animator component

02:56.930 --> 02:57.770
just appear.

02:57.770 --> 02:59.690
So by default it's just going to be none.

02:59.690 --> 03:01.930
Something like this basically means empty.

03:02.050 --> 03:07.660
So what we need to do, we need to select this animator component of this player game object and drag

03:07.660 --> 03:08.700
it into this field.

03:08.700 --> 03:10.020
So we're going to have the reference.

03:10.020 --> 03:12.780
And then we can set this jump parameter.

03:12.780 --> 03:18.820
So let's take this animator component and let's drag it over to this animator slot or animator field

03:18.860 --> 03:19.340
file.

03:19.340 --> 03:22.500
And now we can see we have player animator reference.

03:22.500 --> 03:25.460
Now we are ready to set this jump parameter.

03:25.460 --> 03:28.620
So let's open up our player script by double clicking on it.

03:28.620 --> 03:30.380
And let's go where we're jumping.

03:30.380 --> 03:36.740
So we're doing over here as you can see if input dot get key key Codespace basically means if we press

03:36.740 --> 03:41.940
down space key at the same time we are standing on the ground, then what we're doing, we're just making

03:41.940 --> 03:45.660
our player jump and then we're setting a ground parameter to false.

03:45.660 --> 03:48.900
So we also need to set that jump parameter to true.

03:48.900 --> 03:54.100
And we do know once we're gonna set this jump parameter to true it's going to play the jump animation

03:54.100 --> 03:56.700
clip of that player game object right away.

03:56.700 --> 04:01.660
So we're going to do it inside this curly brackets because we're doing we're just making our player

04:01.700 --> 04:02.620
jump over here.

04:02.620 --> 04:07.310
So that's why after making the jump We also need to play the animation clip.

04:07.310 --> 04:08.750
So we're going to use this animator.

04:08.750 --> 04:12.270
So we do know we have the animator reference as you can see.

04:12.270 --> 04:15.710
So I'm going to use this animator in order to set the parameter.

04:15.710 --> 04:17.270
So let's use this animator.

04:17.270 --> 04:21.670
And we're going to use this dot set function and make first packet.

04:21.670 --> 04:24.110
So why we used this set bool function.

04:24.110 --> 04:30.310
Because if we move over to unity we can see in animator component we just created this jump parameter

04:30.310 --> 04:33.550
which is bool parameter which can be true or false.

04:33.550 --> 04:38.070
So that's why we need to use this set bool function in order to set the parameter.

04:38.070 --> 04:39.590
So as a first argument this.

04:39.590 --> 04:42.070
Set bool parameter set bool function.

04:42.070 --> 04:47.470
It's going to take the parameter name in quotation, so make sure your users is spelling it correct.

04:47.470 --> 04:53.910
So make sure you just move to unity and see the see the name of the parameter in this animator tab.

04:53.910 --> 04:56.750
So we can see the parameter name is jump.

04:56.750 --> 05:00.870
So as a first argument we need to pass in quotation the parameter name.

05:00.870 --> 05:05.350
So I'm going to make make sure you just do in quotation inside this quotation.

05:05.350 --> 05:07.400
And the parameter name is dumb.

05:07.400 --> 05:11.200
And the second thing, comma, it's going to take the value that you want to set.

05:11.240 --> 05:17.160
And we do know once we take this parameter to true basically means if we set this parameter to true,

05:17.200 --> 05:20.080
it's going to play the jump animation clip right away.

05:20.080 --> 05:22.480
So we need to set this parameter to true.

05:22.480 --> 05:23.960
So let's set the value.

05:23.960 --> 05:26.320
So second thing it's going to take the parameter.

05:26.320 --> 05:28.160
Uh it's going to take the value.

05:28.160 --> 05:33.160
So we're going to set it to true means we're just taking that parameter and then close that up with

05:33.160 --> 05:34.080
semicolon.

05:34.080 --> 05:40.760
So if you haven't watched that chapter or that section in which uh, chapter or section, we just created

05:40.760 --> 05:43.880
the animation clip, you can go and check that out.

05:43.920 --> 05:47.400
If you just a little bit confused then you can check.

05:47.560 --> 05:51.880
So make sure you just press down Ctrl S in order to save your code.

05:51.920 --> 05:53.600
And let's move over to unity.

05:54.160 --> 05:59.760
So once we press down space Key we're going to able to save which is setting this parameter to true

05:59.800 --> 06:00.760
means checked.

06:00.760 --> 06:06.440
So the jump animation is just going to play right away right after we just make our player jump.

06:06.720 --> 06:11.240
So let's click on this play button in the top and let's have a look on this.

06:15.120 --> 06:17.480
So just wait for a little moment.

06:17.640 --> 06:22.960
So if we press down space key on our keyboard as you can see we just made the jump.

06:22.960 --> 06:27.800
But the problem is that we're not playing our run animation clip again.

06:27.840 --> 06:30.840
We just stuck in jump animation clip forever.

06:30.960 --> 06:36.200
So as soon as this player game object is gonna collide with this ground, then at that moment we need

06:36.200 --> 06:39.080
to play the run animation clip instead of jump.

06:39.160 --> 06:44.120
So what we need if we click on this pause button in the top, in order to pause the game, we need to

06:44.120 --> 06:47.320
set this parameter to false basically means uncheck.

06:47.360 --> 06:51.200
And once we just manually do it, if we just manually do.

06:51.240 --> 06:56.000
And then click on this pause button in the top to play the game one more time, we can see it's now

06:56.000 --> 06:58.000
playing the running animation clip.

06:58.000 --> 06:59.560
So let's get out of play mode.

06:59.560 --> 07:02.760
So we also need to set back this jump parameter to false.

07:02.760 --> 07:03.840
Basically uncheck.

07:03.840 --> 07:08.570
But when we shoot once this player game object collide with this ground, at that moment, we're going

07:08.610 --> 07:10.730
to set this jump parameter to false.

07:10.730 --> 07:16.250
And as we're going to set this jump parameter to false, it's going to play the run animation clip because

07:16.250 --> 07:17.930
we have chosen the condition.

07:17.930 --> 07:23.170
If we select the back transition from this jump to run an inspector, we can just take a look.

07:23.170 --> 07:28.570
If we scroll down we can see if jump parameter is false, then it's going to play the run animation

07:28.570 --> 07:29.010
clip.

07:29.010 --> 07:32.130
So we also need to set back this jump parameter to false.

07:32.130 --> 07:33.210
So let's do that.

07:33.210 --> 07:35.810
So let's open up our player script one more time.

07:36.090 --> 07:39.050
And we're going to move over to this uh collision function.

07:39.050 --> 07:41.330
We do know we're just taking over here.

07:41.330 --> 07:44.370
If we're colliding with uh with this ground or not.

07:44.370 --> 07:47.130
So we're doing over here, as you can see.

07:47.130 --> 07:52.530
So once we collide with this ground, we just are setting this ground parameter to true, as you can

07:52.530 --> 07:52.970
see.

07:52.970 --> 07:57.450
So once we collide with this ground then we're just setting this ground parameter to true.

07:57.650 --> 08:01.130
So true to jump for the next time as well.

08:01.650 --> 08:02.130
Sorry.

08:02.290 --> 08:03.290
Uh, I guess true.

08:03.330 --> 08:03.930
Yes.

08:03.930 --> 08:07.370
So what we're doing we're just setting is ground parameter to true.

08:07.370 --> 08:10.860
So we also need to set back that jump parameter to false.

08:10.860 --> 08:14.300
So what we need, we need to move over to this animator component.

08:14.300 --> 08:17.260
And we're going to use the set bool function one more time.

08:17.500 --> 08:21.460
And first thing we do know it's going to take the parameter name in quotation.

08:21.460 --> 08:22.980
So in our case jump.

08:22.980 --> 08:25.700
So make sure you just spelling it correct to check it.

08:25.700 --> 08:30.340
You can just move over to unity and then animator type tab.

08:30.340 --> 08:32.220
And the second thing it's going to take the value.

08:32.220 --> 08:33.700
So we're going to set it to false.

08:33.700 --> 08:36.060
And let's close that off with semicolon.

08:36.100 --> 08:38.580
And setting it to false basically means unchecking.

08:38.580 --> 08:43.780
And we do know once we're gonna uncheck it's gonna play the run animation clip right away.

08:43.820 --> 08:50.100
And where we just unchecking once whenever this player came up to collide with this crown as you can

08:50.100 --> 08:51.220
see over here.

08:51.420 --> 08:54.860
So firstly we just moving over to animator and then setting.

08:54.860 --> 09:00.300
So basically we're just moving over to this animator of this uh basically player a game object.

09:00.300 --> 09:05.180
And then we're just setting this parameter by this animator component reference.

09:05.380 --> 09:10.230
So let's uh, press down Ctrl s to save our script and let's move to unity.

09:10.710 --> 09:16.550
So as soon as this player came up to collide with this ground, you will see the run animation.

09:16.550 --> 09:20.910
Just gonna play right after this player came up to collide with this ground.

09:20.950 --> 09:23.230
So let's have a look on this as well.

09:23.390 --> 09:26.830
So let's click on this play button in the top to play our game.

09:26.870 --> 09:29.150
And we're going to take a look on that.

09:30.030 --> 09:31.030
So just wait.

09:33.790 --> 09:40.230
And now if we press down space key on our keyboard as you can see it's just playing the jump animation

09:40.230 --> 09:40.790
clip.

09:40.830 --> 09:45.750
As soon as this player GameObject just collide with this ground, we can see this player game object

09:45.750 --> 09:48.150
is now playing the run animation clip.

09:48.190 --> 09:54.070
But once we pressed on space key on our keyboard and just playing the jump animation clip, and as soon

09:54.070 --> 09:58.990
as this player came up to collide with this ground, then it's just playing the run animation clip.

09:58.990 --> 10:00.590
So I'm gonna get out of play mode.

10:00.630 --> 10:03.310
I hope you get the idea that how you can do it.

10:03.350 --> 10:09.870
And one thing we just forgot to do that is to restriction about that rotation.

10:09.870 --> 10:11.350
So let me show you first.

10:11.350 --> 10:16.830
If we select our player GameObject in the hierarchy, then move over to Inspector, then transform and

10:16.830 --> 10:22.750
then play around with Z rotation to this rotation section and play around with z rotation.

10:22.750 --> 10:26.310
We can see our player GameObject is weirdly routining.

10:26.310 --> 10:28.630
So to stop that what we need to do.

10:28.910 --> 10:36.510
Firstly, I'm going to set back z rotation to zero to restore or to register that or to restrict that.

10:36.510 --> 10:41.870
You need to move over to this rigidbody 2D component of this player GameObject, and then scroll down

10:41.910 --> 10:44.270
a bit and then move over to this constraint.

10:44.270 --> 10:47.830
Click there and freeze the rotation about z axis.

10:47.830 --> 10:53.390
Basically check that and now the rotation will be restricted in this z axis.

10:53.390 --> 10:55.870
So it's not gonna rotate like that.

10:55.870 --> 10:56.910
And that is the thing.

10:56.950 --> 11:02.310
And also make sure you just go to inspector then overwrite and then click on this apply all.

11:02.310 --> 11:08.110
So the changes you made it's going to be saved into this player prefab game object as well.

11:09.350 --> 11:12.550
And we're going to press down Ctrl S to save our project.
