WEBVTT

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

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

00:01.460 --> 00:05.900
In this one I want to show you how to make jump and full animations.

00:05.900 --> 00:09.410
And also I want to clean up our code just a little bit more.

00:09.410 --> 00:13.490
So first let's make the animations for Jump and Fall.

00:13.550 --> 00:21.020
We're going to go to animation Window, select animator and then click Create New Clip on the animations

00:21.020 --> 00:24.200
folder we need Player Jump.

00:26.510 --> 00:27.920
And we need one more.

00:27.920 --> 00:30.830
Create new clip player.

00:31.070 --> 00:31.850
Hold.

00:32.510 --> 00:33.530
Very nice.

00:33.560 --> 00:37.040
Now let's select uh graphics folder over here.

00:37.580 --> 00:44.810
Go to Main Character virtual GUI and take this folder animation just one sprite and place it over here.

00:44.810 --> 00:48.380
Sample rate is not important because we have only one frame here.

00:48.710 --> 00:50.990
Now let's select uh jump.

00:52.510 --> 00:53.680
And place it here.

00:53.680 --> 00:55.480
This would be for jump animation.

00:55.750 --> 01:01.330
Now our goal is to switch between these two animations when player goes up or down.

01:01.690 --> 01:06.910
Luckily for us that is super easy to do and we did something similar with the movement before.

01:07.360 --> 01:12.010
We're going to go to animator and we can just delete these two animation states.

01:12.010 --> 01:13.000
We don't need them.

01:13.000 --> 01:18.880
And over here we're going to make new Blend tree which I'm going to call.

01:19.920 --> 01:20.880
Jump.

01:22.410 --> 01:23.250
Very nice.

01:23.250 --> 01:25.290
Now let's go inside of this jump file.

01:25.680 --> 01:26.610
Select it.

01:26.610 --> 01:28.950
And over here we need new parameter.

01:28.950 --> 01:31.080
We cannot use x velocity for this.

01:31.080 --> 01:33.480
For this one we're going to use y velocity.

01:33.480 --> 01:39.210
So we're going to add float parameter here and type y velocity.

01:40.880 --> 01:45.290
Now let's, uh, go to parameters and choose y velocity here.

01:45.560 --> 01:48.350
And now we need to add two motion fields.

01:48.380 --> 01:49.670
Add motion field.

01:49.700 --> 01:50.840
Add motion field.

01:52.640 --> 01:55.580
The one over here going to be player fall.

01:55.700 --> 01:58.490
The second one going to be player jump.

01:59.760 --> 02:05.280
And we're going to uncheck all to my threshold and make minus one and one.

02:05.730 --> 02:07.440
So now we're going to play animation.

02:07.440 --> 02:11.040
And we can see if y velocity is higher than zero.

02:11.190 --> 02:12.270
He's going to jump.

02:12.420 --> 02:14.850
If it's lower than zero he's going to fall.

02:15.450 --> 02:18.000
And we just need to update this parameter in the script.

02:18.000 --> 02:19.320
That's all what we need to do.

02:19.980 --> 02:23.220
And let's go to the player.

02:26.880 --> 02:28.890
And quickly update this parameter.

02:29.710 --> 02:36.880
On the animation, we're going to choose anim set float for the y.

02:36.880 --> 02:40.660
Velocity is going to be our velocity dot y.

02:41.260 --> 02:41.650
For now.

02:41.650 --> 02:44.920
Let's just go there and make sure this is working.

02:44.920 --> 02:46.930
We're going to go back to the unity.

02:50.820 --> 02:51.930
Go to base layer.

02:51.930 --> 02:53.130
Click play.

02:55.920 --> 02:57.060
And we can see we have y.

02:57.060 --> 02:58.140
Velocity is zero.

02:58.140 --> 02:59.370
Now I'm going to try to jump.

02:59.370 --> 03:01.470
And yes we updating the value.

03:01.530 --> 03:07.530
The only goal now is to connect these two states over here, just like we did in the first example.

03:07.530 --> 03:11.130
But this time condition will be something simpler.

03:11.130 --> 03:14.460
We're going to check if he is grounded or not.

03:14.850 --> 03:18.270
And we don't need to do much for that because we already have a collision check.

03:18.270 --> 03:22.650
We just need a bool parameter that would say is grounded.

03:24.080 --> 03:26.150
Then let's make transition from idle.

03:26.150 --> 03:26.930
Move to jump.

03:26.930 --> 03:27.710
Fall.

03:29.270 --> 03:32.000
The condition would be E is grounded.

03:32.000 --> 03:32.840
True.

03:34.360 --> 03:38.680
Has exit time and check transition duration zero.

03:38.710 --> 03:40.600
Now let's make transition back.

03:41.610 --> 03:42.900
This one would say.

03:44.010 --> 03:45.330
Is grounded.

03:45.880 --> 03:46.270
True.

03:46.300 --> 03:47.140
Wait a second.

03:47.140 --> 03:48.700
This was his grounded.

03:48.700 --> 03:49.420
False?

03:49.420 --> 03:50.440
Yes.

03:50.890 --> 03:53.350
And if it's a true, we go back to idle and move.

03:53.350 --> 03:54.100
So.

03:54.580 --> 03:54.910
Yeah.

03:54.910 --> 03:55.270
I'm sorry.

03:55.270 --> 03:56.800
I hope I did not confuse you.

03:56.800 --> 03:58.720
When we go from idle to jump.

03:58.720 --> 04:00.280
We said grounded.

04:00.280 --> 04:00.700
False.

04:00.700 --> 04:05.170
When we're going from full jump to idle move, this should be true.

04:05.200 --> 04:10.960
Transition duration zero has exit time and check for immediate transition between animations.

04:11.970 --> 04:15.060
Now we need to update this parameter in the script as well.

04:15.060 --> 04:20.010
We go back to scripts and over here we type enum set bool.

04:21.080 --> 04:25.550
Is grounded to the boolean we have is grounded.

04:26.960 --> 04:29.090
Okay, let's save this.

04:29.090 --> 04:31.040
Let's go back to unity.

04:32.130 --> 04:33.660
And let's try it out.

04:35.350 --> 04:39.160
I'm gonna jump and we jump in and animation is there.

04:39.340 --> 04:40.750
Jump and fall.

04:40.750 --> 04:42.160
Jump and fall.

04:42.190 --> 04:43.570
How cool is that?

04:43.570 --> 04:44.590
Super cool.

04:44.590 --> 04:45.310
Love it.

04:46.110 --> 04:48.240
Now let's go back to player script.

04:48.240 --> 04:53.040
And here I want to show you a couple of tricks to make your code sort of cleaner.

04:53.040 --> 04:54.540
This is not mandatory.

04:54.540 --> 04:55.620
You don't have to do it.

04:55.620 --> 04:56.640
I just like to do it.

04:56.640 --> 04:58.980
And I want to show you what I'm talking about.

04:58.980 --> 04:59.370
Okay?

04:59.370 --> 05:06.150
So first of all, when you have just one line of code in the method like I have here, in the jump,

05:06.330 --> 05:08.910
you can remove.

05:10.050 --> 05:10.950
This.

05:12.920 --> 05:15.200
You can remove these curly brackets.

05:15.530 --> 05:19.100
Then you can type over here equal sign and bigger sign.

05:19.100 --> 05:23.120
Together they will resolve what is called a lambda expression.

05:23.120 --> 05:27.350
To put it simple, it's like saying this method will do this for us.

05:27.350 --> 05:33.830
So again our velocity equals to new vector two, our velocity dot x and jump force.

05:33.830 --> 05:37.070
And this would work same as the function before.

05:37.070 --> 05:40.400
But because it has only one line of code we can type it like so.

05:40.400 --> 05:46.670
And this will make it a bit, you know, uh, smaller I would say, because before it took so much of

05:46.670 --> 05:51.950
space, but now it only takes this much of space and we still can see what is inside of this function.

05:51.950 --> 05:52.940
So this is how you do it.

05:52.940 --> 05:54.770
And this still would work.

05:54.950 --> 05:56.750
Uh, let's go and make sure of that.

05:58.570 --> 06:00.100
And working as before.

06:00.100 --> 06:00.760
Very good.

06:00.760 --> 06:04.420
But you can do this only if you have one line of code.

06:04.420 --> 06:08.590
If you have more than one, then you would have to open curly brackets.

06:09.280 --> 06:09.640
Uh.

06:11.210 --> 06:14.840
Place it here and do like debug log.

06:14.840 --> 06:16.580
Another line of code.

06:16.580 --> 06:17.120
Okay.

06:18.190 --> 06:21.280
Yeah, so that's how I want to keep it for now.

06:22.920 --> 06:29.550
And another trick, which is very handy if in the if statement, you have only one line of code, just

06:29.550 --> 06:31.650
like I have here in this example.

06:31.980 --> 06:34.830
Then again, you can get rid of curly brackets.

06:34.830 --> 06:39.300
You can remove this and this and make sure you don't have an empty space between them.

06:39.300 --> 06:42.060
And now this would be the same as we just seen.

06:42.060 --> 06:44.820
But it takes less of a space on the page.

06:44.820 --> 06:45.390
Okay.

06:45.630 --> 06:47.490
And it would work the same as before.

06:47.490 --> 06:53.040
But again if you have more than one line of code, then you would have to extend it to curly brackets

06:53.040 --> 06:54.330
and use it like so.

06:56.550 --> 06:58.800
That's the simple way to put it.

06:58.830 --> 07:04.350
We could also do this over here, but I'm going to introduce another collision check later on.

07:04.350 --> 07:05.400
So I'm not going to do it.

07:05.400 --> 07:08.190
I'm going to keep it open with the curly brackets okay.

07:08.190 --> 07:10.080
For the movement as well.

07:10.080 --> 07:12.180
We're going to add some changes later on.

07:12.180 --> 07:13.560
So let's keep it as it is.

07:13.560 --> 07:14.610
We're good to go.

07:14.610 --> 07:15.840
I'll see you in the next video.
