WEBVTT

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

00:00.420 --> 00:01.410
Welcome to the video.

00:01.410 --> 00:04.500
In this one we're going to make a falling platform.

00:04.500 --> 00:06.330
The script is very easy to do.

00:06.330 --> 00:11.400
And this is basically a practice of all what we did before like sort of a combination of it.

00:11.400 --> 00:16.080
I will explain as much as I can when we doing some new things, but things that we did before, I'm

00:16.080 --> 00:17.100
not going to explain much.

00:17.100 --> 00:17.760
All right.

00:18.210 --> 00:20.250
So let's make the falling platform.

00:20.250 --> 00:21.720
It's going to fly in the air.

00:21.720 --> 00:24.510
Then when a player steps on the platform, it's going to fall.

00:24.510 --> 00:26.790
And that's basically all the functionality.

00:27.060 --> 00:28.530
First we need to make GameObject.

00:28.530 --> 00:29.400
So let's do it.

00:29.400 --> 00:31.110
Graphic traps.

00:31.980 --> 00:37.140
Uh following platform, select them both and set pixel per unit to 16.

00:37.530 --> 00:44.280
Then let's take one of the sprites, drag them into the scene, make certain layer uh, trap.

00:45.570 --> 00:54.990
We also need a rigid body on this one rigid body 2D and let's name it as trap Olin platform.

00:54.990 --> 00:57.540
And let me quickly say, why do we need a rigid body.

00:57.540 --> 00:59.670
So we're going to set it to kinematic.

00:59.670 --> 01:02.790
And it's not going to be affected by physics or anything like that.

01:02.790 --> 01:05.520
And it's going to stand over there for example.

01:05.520 --> 01:05.940
Right.

01:05.940 --> 01:11.010
But when we want it to fall, we're going to switch body type from kinematic to dynamic, and it's going

01:11.010 --> 01:11.760
to fall like that.

01:11.760 --> 01:15.210
So that's the only reason we need a rigid body on this platform.

01:15.210 --> 01:20.670
Let's change collision detection to continuous and interpolate interpolate.

01:20.970 --> 01:21.960
Nice.

01:21.960 --> 01:26.880
Now we also need a box collider so we can stand on the platform just like that.

01:26.880 --> 01:29.130
And we need to set layer to ground.

01:29.580 --> 01:31.050
There are other things we need to do.

01:31.050 --> 01:38.430
But first let's set up animations and we're going to go to asset animations traps controllers make a

01:38.430 --> 01:39.180
new one.

01:40.710 --> 01:43.380
Trampoline platform.

01:44.370 --> 01:46.470
Let's put it on the platform.

01:46.470 --> 01:47.760
Yeah, we have animator.

01:47.760 --> 01:48.210
Nice.

01:48.210 --> 01:49.350
Now we need animations.

01:49.350 --> 01:53.490
Let's create and inotropes trap.

01:53.610 --> 01:55.620
All in platform.

01:55.890 --> 01:56.880
Uh, active.

01:58.840 --> 02:01.630
Can I go to graphics traps following platform?

02:01.630 --> 02:03.820
Take these sprites on.

02:03.820 --> 02:04.990
Put them here.

02:04.990 --> 02:06.940
Sample array 20.

02:06.940 --> 02:08.620
Then we need new clip.

02:08.800 --> 02:13.300
And I'm just here I'm just going to select this one and change active to.

02:14.700 --> 02:16.500
Of save it.

02:16.500 --> 02:20.010
Take the off sprite, put it here on the animator.

02:20.010 --> 02:22.050
We're going to select active by default.

02:22.050 --> 02:25.290
And then we're going to transfer to platform off with a trigger.

02:25.960 --> 02:27.130
Deactivate.

02:27.160 --> 02:28.900
Deactivate.

02:31.250 --> 02:33.380
Trigger has exit time and check.

02:34.010 --> 02:35.750
Transition duration zero.

02:35.780 --> 02:36.920
Very nice.

02:36.920 --> 02:38.750
And that's all for the setup.

02:38.780 --> 02:40.280
Now we need a script for this.

02:40.310 --> 02:47.390
I'm going to go to scripts make a new C sharp script trap fallen platform.

02:47.720 --> 02:52.940
The functionality is somewhat similar to the trap soul because we have a movement on this platform,

02:52.940 --> 02:58.070
but I don't see really a reason to make entire inheritance just for one method.

02:58.070 --> 03:02.030
So I think we're just going to write everything from scratch, uh, how it's going to work.

03:02.030 --> 03:06.800
If we just go to play mode right now, it's going to spin the propeller over there, but it doesn't

03:06.800 --> 03:07.910
look like it's flying.

03:07.910 --> 03:09.500
It's standing there flat.

03:09.500 --> 03:15.590
So what I want to do here is to save position above the platform and below the platform.

03:15.590 --> 03:21.380
And this will be the travel distance for the platform and platform going to move between these two positions

03:21.380 --> 03:22.100
real fast.

03:22.100 --> 03:23.870
And it's going to look like it's flying.

03:24.110 --> 03:29.990
So first let's go ahead and save the position just so you understand how it's going to work I'm going

03:29.990 --> 03:34.370
to make public vector three uh waypoints and then we're going to hide it.

03:34.370 --> 03:37.250
But first I want you to see how it's working altogether.

03:37.250 --> 03:39.140
Let's just make it as array.

03:40.170 --> 03:45.120
And let's make serialize field private float travel distance.

03:45.120 --> 03:49.680
And we need serialize field private float, maybe speed just like that.

03:49.680 --> 03:52.770
And I'm going to make it equals to point 75 F by default.

03:52.770 --> 03:55.050
Because it's going to be really small value there.

03:55.200 --> 03:56.370
Now.

03:57.110 --> 03:58.940
In the start over here.

03:58.940 --> 04:00.350
I'm going to do this.

04:00.500 --> 04:02.240
Actually, let's make a method real quick.

04:02.240 --> 04:04.340
Setup way.

04:05.230 --> 04:05.890
Points.

04:05.890 --> 04:06.370
Sorry.

04:06.370 --> 04:07.750
It should be a void over here.

04:07.780 --> 04:08.290
Void?

04:08.290 --> 04:08.680
Yeah.

04:08.680 --> 04:10.600
So how do we set up waypoints?

04:10.600 --> 04:18.010
We're going to have, uh, waypoint array with the length of two because we only need two waypoints

04:18.010 --> 04:18.700
up and down.

04:18.700 --> 04:19.330
Right.

04:19.510 --> 04:22.450
And then I'm going to take waypoint equals to zero.

04:22.450 --> 04:25.570
And I'm going to set it equals to transform position.

04:26.730 --> 04:28.950
Plus the offset for the Y.

04:28.980 --> 04:31.560
So actually first let's decide on the offset.

04:31.560 --> 04:32.820
And this is how it's going to be.

04:32.820 --> 04:39.360
Plot y offset is equals to travel distance divided by two y like that.

04:39.360 --> 04:43.470
Well let's say travel distance of the platform is one.

04:43.470 --> 04:46.500
We want to move it up and down.

04:46.500 --> 04:49.620
But when platform starts it is starting over here.

04:49.620 --> 04:56.880
And if we want to get travel distance of one we just need waypoint on minus five and waypoint on the

04:56.880 --> 04:57.210
five.

04:57.210 --> 05:02.970
Basically we just uh, take the travel distance and divide it by half and then set in one position half

05:02.970 --> 05:04.500
below and half above.

05:04.800 --> 05:05.880
This is how it is.

05:06.030 --> 05:12.390
So waypoint zero is equals to transform.position plus new Vector3 zero y offset zero.

05:12.390 --> 05:13.650
And then.

05:14.340 --> 05:19.740
Second waypoint, with the index one going to use minus y offset.

05:20.130 --> 05:21.060
Very nice.

05:21.060 --> 05:25.470
Let's go ahead to start method and call setup waypoints.

05:25.470 --> 05:28.080
And I just want to show you how it's going to work.

05:28.080 --> 05:30.120
We're going to go back to unity.

05:34.600 --> 05:35.200
Over here.

05:35.200 --> 05:37.870
I want to set the position of the platform to zero.

05:38.440 --> 05:39.520
Just for example.

05:39.520 --> 05:40.510
So it is here.

05:40.510 --> 05:42.850
It has y zero and travel distance.

05:42.850 --> 05:44.440
Let it be one.

05:44.770 --> 05:46.060
Let's go to play mode.

05:47.610 --> 05:51.570
And over here we can see that x position is the same as before.

05:51.570 --> 05:55.080
But y position has zero five and -0 five.

05:55.080 --> 06:01.170
So now when we ask this platform to move to one of the waypoints, it's going to move to minus five.

06:01.910 --> 06:07.010
Then to five minus five, five, minus five five and it's going to look like it's flying.

06:07.010 --> 06:09.230
Basically this is what we need to do.

06:09.260 --> 06:12.170
So now we know how the waypoints are working.

06:12.170 --> 06:13.220
How do we set up them.

06:13.220 --> 06:17.660
I'm going to make it private and I'm going to make update.

06:18.260 --> 06:22.730
And below the update I need method private void handle movement.

06:22.730 --> 06:23.750
Let it be like that.

06:23.750 --> 06:27.650
So here we're going to do Transform.position equals to vector two.

06:27.680 --> 06:34.460
Move towards from Transform.position to a waypoint with a fly speed.

06:34.460 --> 06:36.140
Sorry, we need an index.

06:36.140 --> 06:37.190
I forgot the index.

06:37.190 --> 06:43.880
So let's do private int we point index okay.

06:43.880 --> 06:44.720
Very nice.

06:44.720 --> 06:47.600
So over here we're going to use waypoint index.

06:47.600 --> 06:52.430
And speed will be just speed multiplied by time dot delta time.

06:52.430 --> 06:53.300
Nice.

06:53.300 --> 06:56.330
Now we're going to check if we are close enough to the waypoint.

06:56.330 --> 06:57.770
If uh vector2.

06:57.770 --> 07:05.600
The distance from transform.position to a waypoint index less than 0.1 F, then we are close enough.

07:05.690 --> 07:08.660
We can take waypoint index and do plus plus.

07:08.660 --> 07:16.580
And if waypoint index is bigger or equals to waypoint length, then waypoint index equals to zero is

07:16.580 --> 07:17.960
going to handle movement.

07:18.470 --> 07:21.380
I'm going to call this method in the update handle movement.

07:21.710 --> 07:28.220
And just in case we need to switch it off at some point I'm going to make a boolean over here.

07:28.220 --> 07:30.140
Private bool can move.

07:30.140 --> 07:30.890
Uh yeah.

07:30.890 --> 07:33.950
Let's make it public for now so we can see it later on.

07:33.950 --> 07:34.970
I'm going to hide it.

07:37.410 --> 07:43.050
And over here, if can move equals to false, then return.

07:43.290 --> 07:47.220
Let's save this and let's go see how does it work right now.

07:48.390 --> 07:53.070
So I'm going to set travel distance really low like 0.6 maybe.

07:53.070 --> 07:55.050
And I'm going to set Canmove true.

07:55.050 --> 07:58.380
And we're going to see platform in the action.

07:59.300 --> 08:01.850
And now it's looking nice and like, you know.

08:02.700 --> 08:08.370
Low t reading like how it works if you set lower travel distance to something like 0.4.

08:08.400 --> 08:09.600
Going to be even better.

08:12.270 --> 08:13.050
Yeah.

08:13.080 --> 08:18.630
Now the goal is to land on the platform and detect that we landed on the platform.

08:18.630 --> 08:19.320
Right.

08:20.210 --> 08:24.440
Uh, I'm going to place platform over here and player over here.

08:24.950 --> 08:28.520
So how are we going to detect that player touched the platform?

08:28.520 --> 08:29.750
There are many ways to do that.

08:29.750 --> 08:33.080
And one of them would be to use Trigger Collider.

08:34.640 --> 08:40.190
I think I didn't show you this before, but you can actually add two colliders to the game object and

08:40.190 --> 08:46.010
set one of them as is trigger, and this collider will trigger a method on trigger enter.

08:46.010 --> 08:48.230
We just need to focus on the platform.

08:49.720 --> 08:51.550
Click Edit Collider.

08:52.990 --> 08:56.800
And we need to squeeze it from the sides and from the below.

08:58.000 --> 09:03.790
So this trigger cannot be reached from the sides or from below, because there is a common collider

09:03.790 --> 09:05.530
that will block the movement.

09:05.530 --> 09:09.250
But from the above, it's supposed to be, you know, available.

09:09.250 --> 09:12.490
So over here I'm going to just slightly increase it.

09:12.490 --> 09:17.890
And if you're not sure which collider you are changing, you can see values over here in the collider.

09:17.890 --> 09:22.570
And by dragging them I can see that I'm changing values of the Trigger Collider.

09:22.570 --> 09:23.230
Okay.

09:23.590 --> 09:31.240
So now this collider cannot be entered from the sides or from the below, but it's supposed to be available

09:31.240 --> 09:33.040
from the above of the platform.

09:33.040 --> 09:36.040
So we're going to take the collider and just slightly increase it.

09:36.040 --> 09:39.100
Like so really like just by a bit.

09:39.100 --> 09:44.080
If you're not sure which collider you are changing, you take a look at the variables over here and

09:44.080 --> 09:46.540
if they are changing means you're changing the trigger.

09:47.330 --> 09:48.560
You can see that right?

09:48.590 --> 09:49.100
Okay.

09:49.100 --> 09:51.530
So I'm going to make it somewhat like this.

09:51.530 --> 09:54.410
And let's move this collider over here.

09:54.710 --> 09:57.050
Now we can snap them like so.

09:57.140 --> 09:59.150
And I just want to make sure it is working.

09:59.150 --> 10:01.610
So I'm going to go ahead make on trigger.

10:01.610 --> 10:04.220
Enter on trigger enter to D.

10:05.630 --> 10:07.850
Sheila, I know it's going to work, but I want to.

10:07.880 --> 10:09.170
I want you to see it.

10:09.170 --> 10:09.560
Let's do.

10:09.560 --> 10:10.400
Player.

10:11.120 --> 10:14.360
Player equals to collision GameObject Getcomponent.

10:14.390 --> 10:15.140
Our player.

10:17.040 --> 10:20.700
And if player not equals to null, then debug log.

10:21.240 --> 10:23.490
Platform should fall.

10:23.970 --> 10:24.750
Okay.

10:24.750 --> 10:26.220
Gonna save it.

10:26.670 --> 10:27.600
Go back.

10:29.580 --> 10:31.470
And let me jump on the platform.

10:36.220 --> 10:36.610
Boom.

10:37.650 --> 10:38.970
Platform should fall.

10:39.270 --> 10:40.440
Very nice.

10:40.440 --> 10:43.710
So how do we achieve the falling of the platform?

10:44.220 --> 10:46.230
I think it should fall with a delay.

10:46.260 --> 10:47.580
Not immediately.

10:47.580 --> 10:49.980
And for that we could use a coroutine.

10:49.980 --> 10:53.280
Or we could use, um, invoke.

10:53.310 --> 10:56.190
I never showed you what is invoke, but it also can be used.

10:56.190 --> 10:57.750
So I think it's the time.

10:57.750 --> 11:01.920
Let's go ahead and quickly make a header platform.

11:01.920 --> 11:04.110
All details something like that.

11:04.110 --> 11:07.020
And over here we need serialize field, private float.

11:07.230 --> 11:09.270
Uh whole delay.

11:09.270 --> 11:11.640
I'm going to make it 0.5 by default.

11:11.640 --> 11:12.510
Nice.

11:12.510 --> 11:15.300
Now we're going to make a method.

11:16.320 --> 11:20.010
Private void drop off platform.

11:21.270 --> 11:25.590
Oh let's use switch off platform better.

11:25.830 --> 11:30.090
And in the switch off platform we're going to switch body type of the rigid body.

11:30.090 --> 11:32.280
And also going to increase gravity scale.

11:32.280 --> 11:38.040
So it falls faster I guess and animation should be triggered I guess for that we need a bunch of components.

11:38.130 --> 11:40.890
So let's go ahead and get components over here.

11:42.000 --> 11:49.140
Private Animator, anim Revit Rigidbody, 2d, ARB and we need colliders on the object so we can switch

11:49.140 --> 11:49.740
them off.

11:49.740 --> 11:53.190
And player would not be able to stand on the platform anymore.

11:53.190 --> 11:59.340
So I'm going to do Private Box Collider 2D, but I'm going to make it as array because we have two colliders

11:59.340 --> 12:03.300
and I'm going to just call it colliders then in the wake.

12:04.780 --> 12:10.150
We're going to do anim Getcomponent of animator Richard by the getcomponent of rigidbody.

12:10.150 --> 12:16.420
And for colliders we're going to do equals to getcomponent with the plural over here.

12:16.450 --> 12:16.810
All right.

12:16.810 --> 12:19.870
With the letter S get components of box Collider.

12:20.600 --> 12:24.290
So they all will be in the variables saved.

12:24.290 --> 12:26.000
Now we can go back to the.

12:26.510 --> 12:28.370
Switch off platform over here.

12:28.370 --> 12:33.020
We're going to do anim set trigger off deactivate.

12:33.020 --> 12:36.980
Then RB is kinematic equals to false.

12:36.980 --> 12:44.420
Also I want to set gravity scale to something like 3.5 and RB drag equals 2.5.

12:44.420 --> 12:45.710
This will add a bit of.

12:45.710 --> 12:48.830
The resistance of the air will make it more natural.

12:48.830 --> 12:52.700
And also we want to take let's do for each loop.

12:52.700 --> 12:56.930
And here we're going to use Box Collider as a variable box collider 2D.

12:56.930 --> 13:03.110
So for each box Collider Collider in colliders that we collected before.

13:04.350 --> 13:09.060
We're going to do collider enable enabled equals to false.

13:09.060 --> 13:10.980
So this will switch off the collider.

13:11.010 --> 13:12.030
Very nice.

13:12.030 --> 13:15.030
Now as I said before we should call this method with a delay.

13:15.060 --> 13:16.350
This is how you call method.

13:16.350 --> 13:18.930
With a delay you can type invoke.

13:19.660 --> 13:25.240
Then in a quotation marks, you need to type the name of a method like this switch of platform.

13:25.240 --> 13:31.570
And then after a comma, you give it time as a delay and we have something drop delay.

13:32.280 --> 13:33.090
What's the variable?

13:33.090 --> 13:33.990
Full delay.

13:34.020 --> 13:38.280
Okay, uh, before we go and test this, I want to say something here.

13:38.280 --> 13:41.820
It is not very good practice to type methods in quotation marks.

13:41.820 --> 13:43.710
And this is what I learned with experience.

13:43.710 --> 13:46.110
Because you can make a mistake over here.

13:46.110 --> 13:47.040
It will not work.

13:47.040 --> 13:50.820
Also, you may change methods name later on and it will not change it over here.

13:50.820 --> 13:53.370
So it's really difficult to keep track of this.

13:53.370 --> 13:59.070
So instead we can type name of parenthesis switch off platform.

13:59.460 --> 14:00.450
I'm gonna work as well.

14:00.450 --> 14:03.810
But now if you change method it's going to change it here as well.

14:04.290 --> 14:09.120
Okay let's save this and let's go and see how platform is falling.

14:15.900 --> 14:17.550
So it is flying over there.

14:17.550 --> 14:18.930
I'm going to jump on the platform.

14:18.930 --> 14:19.560
Boom!

14:20.010 --> 14:21.060
And it falls.

14:22.030 --> 14:23.320
Not that bad.

14:23.320 --> 14:25.180
Yeah, I like it.

14:25.570 --> 14:27.250
Was sort of jittering, I think.

14:27.250 --> 14:30.520
So I just need to see it once again because felt glitchy.

14:31.840 --> 14:33.580
I'm going to just take the platform.

14:39.360 --> 14:42.240
Also, you'll see that all of the platforms are flying together.

14:42.240 --> 14:44.820
Now we're going to fix it with a randomizer.

14:44.820 --> 14:46.200
But first let's see it.

14:49.710 --> 14:51.660
Oh, you see how it's struggling to fall.

14:51.660 --> 14:53.910
And I know why it's struggling to fall.

14:53.940 --> 14:56.010
Because it's affected by gravity.

14:56.010 --> 15:01.050
But also it is trying to move with a this handle movement.

15:01.770 --> 15:07.650
So we need to go to the switch off platform and make and move equals to false.

15:08.130 --> 15:08.610
Yeah.

15:09.830 --> 15:11.630
Uh, let's go ahead.

15:11.780 --> 15:12.980
Double check this.

15:20.340 --> 15:21.030
Yeah.

15:21.800 --> 15:23.840
Better, I like it.

15:26.120 --> 15:29.450
Now there are a couple of things I want to do to improve this mechanic.

15:29.450 --> 15:31.550
One of them is to.

15:32.180 --> 15:35.870
Make some sort of impact when you touching the platform.

15:35.870 --> 15:39.440
And second one is to add difference for the movement.

15:39.440 --> 15:44.990
So different platforms flies with a different, you know, cycle because as of now they all fly in synchronically

15:44.990 --> 15:46.190
and I don't like it.

15:47.170 --> 15:48.820
And let's go back to the script.

15:48.820 --> 15:53.230
So regarding the delay for different platforms we're going to go ahead.

15:54.450 --> 15:57.720
And, uh, make a method private void.

15:58.530 --> 16:01.050
Activate platform.

16:01.820 --> 16:03.800
In which we're going to give it a delay.

16:03.800 --> 16:05.390
So let's do float.

16:05.390 --> 16:10.910
Random delay equals to random range.

16:12.890 --> 16:18.710
Range from zero to let's say 0.6 F, so it's about half of the second.

16:18.710 --> 16:22.940
And it can be widely between 0 and 0.5 F actually 0.59 F.

16:22.970 --> 16:23.450
Yeah.

16:23.450 --> 16:26.120
And that will give it different movement for each platform.

16:26.120 --> 16:28.520
And then over here I'm going to do oh wait a second.

16:28.520 --> 16:29.810
This should not be here.

16:29.810 --> 16:31.940
This should be here in the start.

16:32.950 --> 16:33.700
Yeah.

16:33.850 --> 16:35.470
And this one will just do.

16:36.530 --> 16:39.350
And move equals to true just like that.

16:39.350 --> 16:40.880
And we're going to invoke.

16:42.240 --> 16:46.530
Name of activate platform with a random delay.

16:46.560 --> 16:47.100
Yeah.

16:47.100 --> 16:51.330
Also, I have a trick how to make it all cleaner, but I'm going to show it to you later on.

16:51.480 --> 16:55.590
Uh, now we need to make the impact when you touch the platform.

16:57.300 --> 17:02.070
Let's make a variable sterilized field private float impact speed.

17:02.070 --> 17:05.250
I'm going to make it equals to three by default because I know it's going to work.

17:05.250 --> 17:09.720
And also we need serialize field private float impact duration.

17:09.720 --> 17:12.240
And also I know 0.15 is a good value.

17:12.240 --> 17:15.810
So this is how fast the platform will move when you touch it.

17:15.810 --> 17:19.110
And this for how long platform will move when you touch it.

17:19.110 --> 17:23.340
And we also need a timer private float impact timer.

17:23.340 --> 17:24.900
Now this is how it's going to work.

17:24.900 --> 17:27.180
We're going to decrease timer all the time.

17:27.180 --> 17:31.680
And then when we set value to a positive value then we're going to be decreased from a positive value

17:31.680 --> 17:32.520
to negative.

17:32.520 --> 17:35.910
And a while value is positive we're going to move the platform.

17:36.850 --> 17:38.710
Let's go and make a method.

17:40.990 --> 17:42.100
Somewhere here.

17:42.550 --> 17:47.860
Private void handle impact in which we're going to do this.

17:47.860 --> 17:53.500
If impact timer is less than zero, then return.

17:53.920 --> 17:55.210
Also, we're going to do.

17:55.210 --> 17:57.220
Actually, let me just show you how it's going to work.

17:57.220 --> 18:00.460
I'm going to do impact timer minus equals time dot delta time.

18:00.460 --> 18:05.170
Since delta time is sort of a time in seconds, we're going to decrease this timer all the time while

18:05.170 --> 18:06.190
it is bigger than zero.

18:06.190 --> 18:08.470
If it's less than zero it's not going to work.

18:08.680 --> 18:10.180
I'm going to do debug log.

18:12.250 --> 18:13.420
Move platform.

18:16.070 --> 18:19.610
Now let me make this value public so I can show you how it's going to work.

18:21.870 --> 18:23.640
Let's go to unity.

18:29.470 --> 18:31.450
We can see we have impact timer.

18:31.450 --> 18:34.720
And if I set it to a positive value like three.

18:36.530 --> 18:36.740
Huh?

18:37.040 --> 18:39.350
Oh, I forgot to call method in the update.

18:39.350 --> 18:40.220
I'm so sorry.

18:41.520 --> 18:42.090
Did I not?

18:42.090 --> 18:43.620
Yeah I did not okay.

18:43.650 --> 18:44.610
Update.

18:45.060 --> 18:46.980
Handle impact okay.

18:52.870 --> 18:59.020
So I have a bug timer and if I set it, let's say to three you're going to see how it's decreasing itself.

18:59.580 --> 19:04.530
And we can just move platform down while the timer decreasing itself.

19:05.270 --> 19:11.660
And if we set it to 0.1 while this is happening, we're going to move the platform or another value.

19:11.660 --> 19:15.110
Basically, while value is positive, we're moving the platform down.

19:15.560 --> 19:17.210
So we're going to go over here.

19:17.840 --> 19:25.190
And do transform position equals to vector to move towards from, transform position to and we just

19:25.190 --> 19:29.810
need a position below the platform like current position minus ten on the Y.

19:29.840 --> 19:30.530
Something like that.

19:30.530 --> 19:38.630
So I'm going to do to uh transform position plus vector three dot down multiply it by some number like

19:38.630 --> 19:39.170
ten.

19:39.170 --> 19:42.710
You just need a vector three below the current one we have.

19:42.710 --> 19:48.650
And it's going to have speed that we use to do impact is impact speed.

19:49.490 --> 19:50.150
Impact.

19:50.150 --> 19:52.160
Speed multiplied by time.

19:52.310 --> 19:53.180
Delta time.

19:53.630 --> 19:56.150
I'm going to press enter over here so you can see it.

19:56.150 --> 19:59.300
And that's all what we need to do for the impact actually.

19:59.880 --> 20:01.440
Nice nice, nice nice.

20:01.440 --> 20:05.790
Now we only want to start the timer every time we enter in the trigger.

20:05.790 --> 20:07.170
So I'm going to do this.

20:07.890 --> 20:11.790
Impact timer equals to impact duration.

20:11.790 --> 20:17.160
And also we want to trigger this only once because if we do not switch off possibility of triggering

20:17.160 --> 20:20.760
the impact then you will just push platform down all the time.

20:21.060 --> 20:22.560
So let's go.

20:24.320 --> 20:25.670
Make this private.

20:26.570 --> 20:27.620
Here I'm going to do space.

20:27.620 --> 20:31.070
So it's different and let's do privatebool.

20:32.580 --> 20:35.010
Impact, uh, happened?

20:35.010 --> 20:36.600
Maybe impact happened.

20:36.600 --> 20:37.320
Okay.

20:37.470 --> 20:38.430
Impact happened.

20:39.070 --> 20:41.020
So it's going to be false by default.

20:41.350 --> 20:42.280
But then.

20:43.450 --> 20:44.320
Over here.

20:44.320 --> 20:52.030
Actually, maybe over here, if impact happened, then return cannot be impacted anymore.

20:52.570 --> 20:56.440
And on the enter we're going to do impact happened equals to true.

20:56.440 --> 20:58.630
So we can trigger it only once.

20:58.630 --> 20:59.890
Let's save this.

20:59.890 --> 21:02.080
Let's go back to unity.

21:04.570 --> 21:07.030
I'm going to duplicate the platform.

21:07.330 --> 21:08.920
Hey, duplicate.

21:08.920 --> 21:09.640
Yeah.

21:10.090 --> 21:13.540
And let's maybe place a couple of more here.

21:17.050 --> 21:18.550
So we have platforms.

21:18.760 --> 21:21.880
They line weight, they line together.

21:21.880 --> 21:22.270
Why?

21:22.270 --> 21:24.010
Why they are flying together.

21:25.620 --> 21:27.090
Want them to fly differently.

21:27.090 --> 21:28.200
Let me double check.

21:29.690 --> 21:33.320
Now, because this can move is set to true by default.

21:33.320 --> 21:36.050
Let's select the platforms and make them false.

21:40.360 --> 21:40.840
Yeah.

21:40.840 --> 21:42.460
Now they're flying differently.

21:42.790 --> 21:44.110
I'm going to jump on the platform.

21:44.110 --> 21:45.940
There is impact and it's falling.

21:46.300 --> 21:47.620
Very pretty impact.

21:47.620 --> 21:48.700
I really like it.

21:49.490 --> 21:51.080
Feels natural.

21:51.170 --> 21:51.530
Boom!

21:51.830 --> 21:52.820
And it's falling.

21:56.990 --> 21:57.620
Yay!

21:57.650 --> 21:59.840
So fallen platform is finished.

22:00.410 --> 22:02.690
Took a bit of time, but I hope you like it.

22:02.690 --> 22:03.470
How it works.

22:03.470 --> 22:04.430
I'm going to switch.

22:04.430 --> 22:07.730
I mean, delete this and let's go.

22:07.730 --> 22:08.690
Here.

22:08.690 --> 22:09.350
Hide.

22:09.350 --> 22:10.580
This can move.

22:10.580 --> 22:11.210
Boolean.

22:13.080 --> 22:13.470
Private.

22:13.470 --> 22:15.720
Also, let's make sure it is false by default.

22:16.860 --> 22:17.940
And then.

22:19.010 --> 22:21.830
Oh, I promise to you how to clean this up.

22:21.830 --> 22:28.070
So actually, you can turn a start method into a coroutine and unity will start method anyway.

22:28.070 --> 22:32.210
So if it's a coroutine, coroutine of the start method will be started as well.

22:32.210 --> 22:34.640
So we can do I enumerator over here.

22:34.640 --> 22:37.520
Then we can do calculation of delay.

22:37.520 --> 22:40.970
Then we can do yield return new waitforseconds of random delay.

22:40.970 --> 22:43.550
And then we can make can move equals to true.

22:44.000 --> 22:47.540
I don't know if it's a good idea, but there is a possibility to do that.

22:47.540 --> 22:50.360
And I wanted you to know about this one okay.

22:50.360 --> 22:51.500
Let's save this.

22:51.500 --> 22:55.100
Let's go ahead and make prefab out of the fallen platform.

22:57.390 --> 23:03.150
If you want to recreate the platform after the fallen, you can do it the same way as we did with the

23:03.150 --> 23:03.690
arrow.

23:03.720 --> 23:08.190
You already know how to do that, so I'm just going to make it as a prefab.

23:09.770 --> 23:11.000
Gonna test it once again.

23:11.000 --> 23:13.610
And I'm going to say thank you for paying attention.

23:13.610 --> 23:15.410
Let's go to the next video.
