WEBVTT

00:00.000 --> 00:00.510
Hello guys.

00:00.510 --> 00:01.440
Welcome to the video.

00:01.440 --> 00:05.610
In this one I want to show you one of the traps we are going to make.

00:05.610 --> 00:10.020
This is more like a moving trampoline rather than a trap.

00:10.020 --> 00:11.160
But still it is nice.

00:11.160 --> 00:12.510
And I want to show you how to do that.

00:12.510 --> 00:17.520
Okay, so I think I'm going to place this trampoline over here while we're testing it.

00:17.520 --> 00:21.090
So I'm going to just delete this trap from here.

00:21.090 --> 00:22.140
I don't need it.

00:22.260 --> 00:29.010
And I want to take this block over here, select it, and I want to move it to the left just a bit.

00:29.010 --> 00:33.000
So I have sort of a space to jump up okay.

00:33.000 --> 00:36.750
Now let's go to Asset graphic.

00:38.900 --> 00:40.490
We need traps.

00:40.490 --> 00:42.410
And there is this trampoline.

00:42.500 --> 00:45.920
So this has an idol and jump animation.

00:45.920 --> 00:49.490
We're going to select both of them dual pixel per unit 16.

00:49.940 --> 00:52.160
And I'm going to drag one of them here.

00:52.160 --> 00:54.620
Let's change certain layer to.

00:55.300 --> 00:56.740
Uh, trap.

00:57.190 --> 01:00.880
I think we can have all of the components on one game object for this one.

01:00.880 --> 01:04.540
So I'm going to do trap trampoline.

01:04.660 --> 01:05.620
All right.

01:06.100 --> 01:13.090
Now let's go to Assets Animations here I think it's time to create folder for traps.

01:13.770 --> 01:14.700
Sorry.

01:14.700 --> 01:15.540
This should be.

01:16.340 --> 01:17.210
Trumps.

01:17.210 --> 01:19.490
Let me take this.

01:19.490 --> 01:26.960
Put it into a folder and inside I want to make an animator controller for Trump.

01:26.960 --> 01:28.610
Trampoline.

01:28.640 --> 01:31.100
AC animator controller.

01:31.680 --> 01:34.320
Then I drag it on the object.

01:35.440 --> 01:39.280
And also we need a box collider for this one.

01:39.550 --> 01:41.230
But this one going to be a trigger.

01:41.230 --> 01:43.210
Let me focus on a trap.

01:43.450 --> 01:43.960
Yeah.

01:43.960 --> 01:46.690
And uh, we're going to just.

01:47.980 --> 01:53.710
Place it somewhere here and trigger Collider for this one will be somewhere here.

01:53.710 --> 01:55.600
Okay, this is good.

01:56.110 --> 01:59.710
Now let's go and make some animations.

01:59.710 --> 02:00.820
It's over here.

02:00.820 --> 02:01.780
Create.

02:02.140 --> 02:05.890
I'm going to do trampoline idle.

02:07.220 --> 02:08.870
We're going to go to graphics.

02:09.420 --> 02:14.400
Trump's trampoline, could the ideal one then create a new one?

02:15.410 --> 02:16.520
Trumbo.

02:17.120 --> 02:19.700
Lane activated.

02:19.760 --> 02:20.300
Okay.

02:20.300 --> 02:23.090
And for this, we need these sprites over here.

02:23.090 --> 02:24.770
Sample rate going to be.

02:25.720 --> 02:28.540
20 and let me see the animation.

02:30.330 --> 02:31.920
Yeah, this is good, I think.

02:31.950 --> 02:33.660
You okay?

02:33.780 --> 02:36.270
Let's select this animation.

02:37.860 --> 02:38.970
Uh, traps.

02:40.040 --> 02:42.350
Trampoline activated.

02:42.350 --> 02:46.160
And I'm going to uncheck loop time because I need it to be activated only once.

02:46.400 --> 02:47.510
Just to be sure.

02:49.180 --> 02:52.720
Then on the animator, I think we just need a trigger.

02:52.720 --> 02:53.950
Activate.

02:56.310 --> 03:00.030
And we're going to make transition to activate it with a trigger.

03:01.260 --> 03:06.420
Activate has exit time and check transition duration zero, but transition back.

03:06.420 --> 03:10.860
Going to have an exit time of one with the transition duration zero.

03:11.010 --> 03:12.090
Nice.

03:12.120 --> 03:17.850
Now we need a script that will detect player and push it up when we need to.

03:17.880 --> 03:23.610
For that, I'm going to make a new method on the player script because we need to push player from outside

03:23.610 --> 03:29.430
of a script, but functionality can be inside just like a knockback and we are something similar.

03:29.700 --> 03:30.930
Let's go.

03:32.200 --> 03:33.220
Somewhere.

03:33.220 --> 03:35.170
Maybe, I don't know.

03:35.170 --> 03:36.130
Over here.

03:36.790 --> 03:40.000
I'm going to do public void push.

03:40.090 --> 03:44.860
And for the push we're going to need vector two direction.

03:44.860 --> 03:49.990
So this will define the power that will say how much we're going to push the player.

03:51.510 --> 03:57.900
And we're going to need to pass float duration, because I want to take away control from the player

03:57.900 --> 03:59.250
while we're pushing him.

03:59.250 --> 04:01.350
We're not going to use this only for the trampoline.

04:01.350 --> 04:03.210
We're also going to use this for another trap.

04:03.210 --> 04:05.040
So this will be multifunctional.

04:05.040 --> 04:10.830
And if you don't want to have duration, we can simply pass maybe a zero by default.

04:10.830 --> 04:14.070
So if you don't pass any value to this method it will be zero.

04:14.070 --> 04:18.090
Then we need a private eye enumerator.

04:18.090 --> 04:19.500
We need a coroutine.

04:20.160 --> 04:21.810
Push core.

04:22.080 --> 04:23.520
Core.

04:24.560 --> 04:25.310
Teen.

04:25.790 --> 04:27.230
And this.

04:27.850 --> 04:33.010
Will also take two parameters vector two direction and float duration.

04:33.010 --> 04:37.450
And then we're going to do can be controlled equals to false.

04:37.980 --> 04:39.780
Then we're going to push RB.

04:39.780 --> 04:44.670
But before we do that, I want to reset velocity that player had before we pushed him.

04:44.670 --> 04:51.120
So I'm going to do RB velocity equals to vector 2.0 which is zero zero.

04:51.120 --> 04:53.580
So we're going to stop any velocity we had.

04:53.580 --> 04:55.860
And we're going to give it a new velocity.

04:55.860 --> 05:02.520
And this time I want to use RB add force into direction.

05:02.520 --> 05:04.650
And we're going to type force mode.

05:06.170 --> 05:07.010
Impulse.

05:07.190 --> 05:14.960
So impulse force mode will add an instant velocity to the player, and it's going to be a bit more,

05:14.990 --> 05:19.310
I would say natural because force will be applied by physics engine.

05:19.310 --> 05:22.220
So it's going to be like real nicely.

05:22.220 --> 05:25.070
It's going to feel physically correct.

05:25.070 --> 05:25.700
Yeah.

05:25.910 --> 05:31.100
And then we're going to do yield return new wait for a seconds of duration.

05:31.100 --> 05:33.380
And then we're going to do can be controlled.

05:33.380 --> 05:34.130
True.

05:34.400 --> 05:34.940
All right.

05:34.940 --> 05:36.800
So this is a push coroutine.

05:36.890 --> 05:39.380
And we're going to start it over here.

05:39.380 --> 05:42.950
Start coroutine push coroutine.

05:43.070 --> 05:45.800
And we're going to pass direction and duration.

05:46.160 --> 05:46.790
Very well.

05:46.790 --> 05:48.980
Nothing else for now but.

05:50.050 --> 05:50.650
Sorry.

05:50.650 --> 05:53.230
Maybe you need to see this before we do this.

05:53.230 --> 05:55.720
I also want to go to the update.

05:57.680 --> 06:03.890
And here, if we return from a method and player cannot be controlled, we still need to update his

06:03.890 --> 06:04.520
animations.

06:04.520 --> 06:12.050
But I don't want to break execution order over here, so I'll just call this handle animation.

06:14.210 --> 06:16.880
And I will call handle collision.

06:17.700 --> 06:18.300
Just in case.

06:18.300 --> 06:22.020
So maybe if he'll be pushed into the wall, he can just do a wall slide.

06:22.020 --> 06:22.590
Okay.

06:22.860 --> 06:23.670
Very nice.

06:23.670 --> 06:25.530
That's all the code we need here.

06:25.530 --> 06:28.110
Now let's go back to unity.

06:28.110 --> 06:35.070
And in the scripts we want to make C sharp script trap, trampoline.

06:35.070 --> 06:36.150
It's not really a trap.

06:36.150 --> 06:40.680
It doesn't do anything bad, I guess, but let's keep it within one, you know?

06:40.950 --> 06:41.370
Uh.

06:43.930 --> 06:48.310
Spectrum, I don't know, like all together, all of them will be traps.

06:48.310 --> 06:49.090
Yeah.

06:49.090 --> 06:53.800
So on this trap, we need to detect if player entered the trigger.

06:53.800 --> 06:57.430
So on trigger enter 2D, um player.

06:57.430 --> 06:59.620
Player equals to man.

06:59.620 --> 07:01.150
Now I wish I would use just tag.

07:01.150 --> 07:03.340
I think it would be more.

07:03.610 --> 07:05.770
I think it would be faster to type.

07:06.190 --> 07:11.980
Yeah this one then if player not equals to null then player push.

07:12.560 --> 07:15.230
And here we need to pass a bunch of variables.

07:15.770 --> 07:24.980
So one of them will be, uh, serialized field private vector two push direction and serialized field.

07:24.980 --> 07:26.660
Private float.

07:27.080 --> 07:28.610
It's going to be, um.

07:30.920 --> 07:34.610
Duration, and I want to make it 0.5 by default.

07:36.350 --> 07:37.070
Yeah.

07:37.310 --> 07:39.590
Also, I have an idea.

07:39.590 --> 07:46.430
But before I tell you about this idea, let's just try push direction and duration here.

07:46.430 --> 07:50.480
Yeah, let's just save this and let's go back to unity.

07:52.390 --> 07:54.310
Now there is this trampoline.

07:54.520 --> 07:56.770
Oh, something else here I forgot.

07:57.600 --> 08:00.540
Let's go to script.

08:00.540 --> 08:04.530
Make a private animator anim.

08:05.190 --> 08:11.250
And over here I'm going to do anim set trigger.

08:11.830 --> 08:12.730
Activate.

08:13.270 --> 08:15.640
And we need to get component of that activate.

08:15.640 --> 08:17.140
I think we can just do return.

08:17.140 --> 08:17.770
Why not?

08:19.010 --> 08:19.430
Yet to come.

08:19.700 --> 08:20.000
Wait.

08:20.000 --> 08:20.990
This will be.

08:20.990 --> 08:21.230
Yeah.

08:21.230 --> 08:23.630
This can be activated a couple of times, not just once.

08:23.630 --> 08:24.890
So I'll do.

08:26.430 --> 08:27.270
Awake.

08:28.970 --> 08:30.710
And you get component of animator.

08:30.740 --> 08:31.490
Nice.

08:31.490 --> 08:32.780
Now let's save this.

08:32.780 --> 08:34.730
Let's go back to unity.

08:36.650 --> 08:43.520
I'm just going to put the script on the trampoline like so, and push direction will define how far

08:43.520 --> 08:47.210
it is pushed to the left or right on the x.

08:47.210 --> 08:53.780
So this is x velocity and y velocity will define push up I think for this one it's not supposed to be

08:53.780 --> 08:57.260
pushed uh, to the left or right only up.

08:57.260 --> 09:01.730
So I'm going to put maybe 25 on the Y.

09:02.810 --> 09:04.640
Let's go to the game window.

09:07.310 --> 09:08.120
And.

09:10.090 --> 09:10.870
A subway.

09:12.310 --> 09:13.480
Oh is trigger.

09:14.280 --> 09:15.810
Let's do is trigger.

09:16.390 --> 09:21.820
And now I'm supposed to be able to walk into this trampoline and I'm going to be pushed up.

09:22.090 --> 09:23.230
Yay!

09:23.530 --> 09:24.370
Check this out.

09:24.370 --> 09:25.510
Man, this is so fun!

09:27.190 --> 09:27.820
Hahaha!

09:28.210 --> 09:33.460
I love it so much and you still can control the character after the push.

09:34.220 --> 09:34.910
Yeah.

09:36.480 --> 09:37.560
This is so good.

09:37.560 --> 09:38.670
I love it so much.

09:38.670 --> 09:45.810
Now this object, by the look of it, supposed to push the player only into direction.

09:45.810 --> 09:47.760
It is like going up right?

09:47.760 --> 09:51.390
And we can see the animation is going into this direction.

09:51.840 --> 09:58.260
Uh, luckily for us, we can see that up vector of this object is also going up.

09:59.960 --> 10:02.510
That's the transform of it.

10:02.510 --> 10:06.020
And we can see the yellow arrow or green green arrow.

10:06.020 --> 10:06.320
Sorry.

10:06.320 --> 10:07.130
I'm colorblind.

10:07.130 --> 10:09.440
It's difficult for me to define colors.

10:09.440 --> 10:10.400
I think it's green.

10:10.400 --> 10:12.470
So green arrow pointing up.

10:12.650 --> 10:16.100
That is a y of the object.

10:18.500 --> 10:19.010
Yeah.

10:19.010 --> 10:23.030
If we go here and click 2D now, it's going to be 3D.

10:23.030 --> 10:26.420
And we can see that green is responsible for the arrow up.

10:26.420 --> 10:28.910
So we can go to the script.

10:29.270 --> 10:39.410
And instead of using push direction like that we can use vector dot up and we can multiply it by power.

10:39.410 --> 10:41.780
Let's do serialize field private.

10:42.600 --> 10:43.410
Load.

10:44.370 --> 10:45.810
Push power.

10:46.780 --> 10:47.500
Nice.

10:47.500 --> 10:53.020
Now I don't need a push direction because anyway, we're not controlling X over here.

10:53.020 --> 10:54.310
We only controlling y.

10:54.310 --> 10:59.350
So by typing vector two dot up we're going to have zero and one.

10:59.350 --> 11:05.140
And we can just multiply it by push power just like that.

11:05.500 --> 11:07.090
Let me remove this one.

11:08.160 --> 11:11.250
And sorry, this one should be multiplied by push power.

11:11.790 --> 11:14.100
Now I can save this.

11:14.610 --> 11:22.980
And because this arrow is pointing up and we push in player according to the place where arrow is pointing,

11:22.980 --> 11:24.360
let me do 25.

11:24.360 --> 11:26.100
Push power over here.

11:26.280 --> 11:26.790
Yeah.

11:26.790 --> 11:27.690
We can.

11:27.690 --> 11:28.500
Sorry.

11:29.620 --> 11:34.240
We can take this trampoline and we can rotate it, maybe like that.

11:34.810 --> 11:42.790
And now when we rotate in the object, and now once object is rotated just a bit, his up vector goes

11:42.790 --> 11:43.600
to the left.

11:43.600 --> 11:49.180
If yours looks different, you need to go here and change from global to local.

11:49.180 --> 11:53.350
Okay, so we can rotate object let's say by 90 degree.

11:53.350 --> 11:56.800
And now the up arrow goes here.

11:56.800 --> 12:04.360
And because we push in player with the vector dot up multiplied by push power play are going to be pushed

12:04.360 --> 12:05.170
to the left.

12:05.170 --> 12:07.600
And we do need to adjust vector over here.

12:07.600 --> 12:09.130
We can just rotate the drop.

12:09.130 --> 12:11.260
And that will do everything for us.

12:11.260 --> 12:13.840
Now let's go ahead and try this.

12:14.990 --> 12:15.680
Oh, no.

12:16.940 --> 12:18.560
Didn't work for some reason.

12:18.590 --> 12:20.300
Wait, let me check that.

12:23.460 --> 12:24.390
Supposed to work.

12:24.390 --> 12:25.890
I just tested this.

12:25.890 --> 12:27.570
I'm doing something wrong.

12:29.710 --> 12:31.420
Vector two dot app.

12:32.710 --> 12:33.550
Oh, sorry.

12:33.550 --> 12:34.120
Not vector.

12:34.120 --> 12:35.110
I am so sorry.

12:35.140 --> 12:36.760
Transform app.

12:36.760 --> 12:41.710
We need to use transform app because we want to have up direction of this object.

12:41.710 --> 12:42.220
Yeah.

12:42.580 --> 12:43.420
My bad.

12:43.420 --> 12:45.430
So now this is how it's going to be.

12:46.170 --> 12:50.910
And because this is transform up for this object, this is going to be multiplied with a push power.

12:50.910 --> 12:54.900
And now we go here and queue.

12:55.410 --> 12:58.830
And very cool I love it so much.

12:58.830 --> 13:01.530
So this is it for the trampoline.

13:01.770 --> 13:04.710
Let me make it as a prefab and let me try something.

13:04.710 --> 13:11.790
I'm going to make it as a prefab and let's say this one will be zero over here I'm going to apply.

13:11.790 --> 13:13.470
Oh it's not needed okay.

13:13.560 --> 13:18.360
And another trap I want to place over here.

13:22.570 --> 13:28.060
This is this feels, um, wrong because we don't have any platform here.

13:29.080 --> 13:30.760
Well, let's say we have a platform there.

13:30.760 --> 13:32.200
Why not just quickly?

13:34.790 --> 13:35.600
Just like that.

13:36.260 --> 13:39.740
And now we can make some sort of chain of movement.

13:41.160 --> 13:41.850
You.

13:43.290 --> 13:45.480
And this is so fun, I love it.

13:50.210 --> 13:50.780
Yeah.

13:50.780 --> 13:51.230
Cool.

13:51.230 --> 13:51.710
Right?

13:51.710 --> 13:55.910
And if you want to increase the push power, you can just change the variable over here.

13:55.940 --> 14:00.230
Now I'm going to remove this I'm just going to place this somewhere.

14:01.300 --> 14:03.250
Like at someplace interesting.

14:05.230 --> 14:06.460
Maybe just here.

14:07.550 --> 14:08.330
Why not?

14:09.440 --> 14:09.620
Yeah.

14:09.620 --> 14:10.490
Let it be there.

14:10.520 --> 14:16.520
Now I'm going to, uh, save the project, and we're going to go to the next video.
