WEBVTT

00:00.020 --> 00:00.470
Hello guys.

00:00.470 --> 00:01.490
Welcome to the video.

00:01.490 --> 00:06.410
In this one I want to show you how to make a trap with a spiked ball.

00:06.410 --> 00:09.770
Just want to make a trap that would swing in the air from left to right.

00:09.770 --> 00:14.660
And there are many ways to do that, but the way I want to use is more like a physically accurate.

00:14.660 --> 00:15.320
I would say.

00:15.320 --> 00:20.390
I want to push the trap once, and it's going to swing by itself the rest of the time.

00:20.390 --> 00:23.720
So how it's going to be let's go ahead to graphic traps.

00:23.720 --> 00:24.890
Spiked ball.

00:24.890 --> 00:29.540
Let's take these two set pixel per unit 16 and then hit apply.

00:29.990 --> 00:35.660
And I think we need some sort of a base for this trap where we can attach it.

00:35.660 --> 00:37.070
And let's go to.

00:38.580 --> 00:39.570
Terrain.

00:40.050 --> 00:42.210
And over here we have a bunch of things.

00:43.500 --> 00:47.670
I think we can use this sprite over here just to make it, um.

00:48.630 --> 00:50.280
Look like a base of a trap.

00:52.040 --> 00:53.360
So I'm going to drag.

00:54.580 --> 00:56.650
This fall.

00:57.650 --> 01:00.440
Square to the scene it's going to be.

01:02.990 --> 01:06.260
And maybe this one could be a bit smaller.

01:06.770 --> 01:07.880
Um, let me think.

01:07.880 --> 01:10.010
Yeah, let's make it as my 0.5.

01:10.010 --> 01:10.640
Maybe.

01:11.350 --> 01:13.240
Sorry we need like this.

01:13.240 --> 01:14.860
And then point five.

01:15.490 --> 01:15.670
Yeah.

01:15.670 --> 01:16.630
It looks good to me.

01:17.200 --> 01:21.790
Just so we can place it somewhere in the middle of the level as well.

01:21.790 --> 01:24.040
Now this is going to be the base for this trap.

01:24.040 --> 01:25.510
Let's say it's going to be here.

01:25.930 --> 01:30.400
Then we're just going to call it as, um, base.

01:31.430 --> 01:33.680
Then let's make a parent for this one.

01:33.680 --> 01:34.610
It's going to be trap.

01:35.610 --> 01:38.190
Spiked ball.

01:38.430 --> 01:41.100
Nice, then.

01:42.320 --> 01:45.560
This object over here should have a bunch of components.

01:45.980 --> 01:48.800
One of them would be distance.

01:49.220 --> 01:52.730
Join 2D and rigidbody for this one should be static.

01:52.730 --> 01:57.740
So this rigidbody will not move and it will serve as a base for the swing trap.

01:57.740 --> 01:59.720
Now let's go to graphics again.

01:59.720 --> 02:01.520
Trap spike ball.

02:01.520 --> 02:03.020
Let's take this ball.

02:03.020 --> 02:04.760
Drag it into the scene.

02:05.150 --> 02:07.610
Let's make it as traps.

02:07.970 --> 02:12.530
We want to put Circle Collider on this so it can damage the player is trigger.

02:14.170 --> 02:20.620
I think it's okay if we make this collider a bit smaller so it's easier for player to play and maybe

02:20.620 --> 02:23.140
like yeah, point 65 looks good.

02:23.560 --> 02:28.030
Now on this object over here we just need to add a rigid body.

02:29.760 --> 02:31.260
And it should be dynamic.

02:31.260 --> 02:35.130
Let's change collision detection to continuous interpolate.

02:35.220 --> 02:39.630
Then we're going to make it as a child of a spiked base like so.

02:39.630 --> 02:42.780
And on the base we have this distant joint.

02:43.230 --> 02:48.420
We can take the spiked ball and drag it to this field connected rigid body.

02:48.420 --> 02:52.830
Now, believe me or not, this will work as it is even now.

02:54.490 --> 02:56.590
It's a swing trap already.

02:56.590 --> 03:00.880
I can just move it here and it's gonna hang like that.

03:02.040 --> 03:02.970
Very cool.

03:02.970 --> 03:10.020
If we wanted to move automatically without interference of developer, we can give it a script.

03:10.020 --> 03:11.880
Let's go to scripts and make.

03:12.860 --> 03:13.910
The sharp script.

03:13.940 --> 03:16.670
Sharp spiked ball.

03:19.280 --> 03:20.270
Oh it's okay.

03:20.300 --> 03:22.850
Then I'm going to select the parent.

03:22.850 --> 03:24.500
Put the script on.

03:25.220 --> 03:29.150
Then inside we can do something like reference to the rigid body we need.

03:29.150 --> 03:30.800
So private RB.

03:31.940 --> 03:33.440
Uh, region by the.

03:34.020 --> 03:40.980
Spike RB and then we want to have serialized field, private float and maybe push force.

03:40.980 --> 03:43.860
Then in the start method we're going to do this.

03:43.860 --> 03:45.840
Let's just do RB.

03:47.450 --> 03:55.010
Actually, let's make vector two push vector equals to new vector two with a push force, and for the

03:55.010 --> 03:56.660
y can be just zero.

03:57.170 --> 03:58.580
Then we're going to do spike rb.

03:58.880 --> 04:03.920
Add force of push vector with a with the force mode impulse.

04:03.920 --> 04:05.030
Just like that.

04:05.300 --> 04:07.280
Now we can save this.

04:07.790 --> 04:09.500
Go back to unity.

04:12.680 --> 04:15.320
We can assign this ball over here.

04:15.680 --> 04:16.580
Come on, boy.

04:17.240 --> 04:17.960
What's up?

04:18.290 --> 04:19.190
Oh, this is rigid.

04:19.190 --> 04:21.350
Body should be rigid body 2D.

04:23.690 --> 04:24.770
A salmon.

04:25.760 --> 04:27.320
Or smooth impulse.

04:27.350 --> 04:29.690
Okay, I'm going to save it.

04:29.690 --> 04:30.590
Go back.

04:32.930 --> 04:37.640
We can drag this to the field and push force can be something like, I don't know, uh.

04:38.480 --> 04:38.840
Ten.

04:38.840 --> 04:39.770
Let's try ten.

04:39.770 --> 04:43.100
And now we can go to play mode and you'll see it will be pushed.

04:43.100 --> 04:49.940
Then it's going to swing like that automatically and it's already dangerous to touch.

04:51.480 --> 04:51.780
Oh.

04:51.810 --> 04:52.710
No damage.

04:52.980 --> 04:53.790
Why not?

04:54.390 --> 04:56.160
Because I forgot to add damage.

04:56.160 --> 04:56.970
Trigger.

04:58.060 --> 04:58.840
Okay.

05:09.880 --> 05:11.350
And I got damaged.

05:11.380 --> 05:12.220
Nice.

05:12.250 --> 05:13.720
Now I want to improve it.

05:13.720 --> 05:17.200
And we can easily do that by adding one more element.

05:17.200 --> 05:19.900
Let's go to graphics traps.

05:19.900 --> 05:20.920
Spike the ball.

05:20.920 --> 05:22.270
There is this chain.

05:22.270 --> 05:25.780
We can take the chain, drag it into the scene somewhere.

05:25.780 --> 05:26.380
Here.

05:26.380 --> 05:29.080
Let's make it as trap.

05:29.740 --> 05:34.990
Going to place it maybe here, and I'm going to make it as child of a drop spike ball.

05:35.380 --> 05:38.620
Now we need to join the chain with the base.

05:38.620 --> 05:40.540
And also we need a couple of more chains.

05:40.540 --> 05:45.190
So I'm going to make one more here and one more over here.

05:46.460 --> 05:46.610
Yeah.

05:46.610 --> 05:49.940
Let's place them with an even distance.

05:53.320 --> 05:53.530
Yes.

05:53.530 --> 05:54.850
Something like this will do.

05:55.700 --> 05:56.870
Okay, I like it.

05:58.500 --> 05:59.940
Should we make bigger distance?

05:59.940 --> 06:01.830
I don't know, looks looks good to me.

06:01.830 --> 06:03.210
So I'm going to keep it this way.

06:03.480 --> 06:03.840
Yeah.

06:03.840 --> 06:08.130
And we need to join these chains with a hinge joint to D.

06:08.700 --> 06:13.050
We're going to add hinge join to D on this game object.

06:13.470 --> 06:14.940
And we're going to go to chain.

06:14.940 --> 06:19.320
Let's select all of them actually and add component of a hinge joint.

06:19.350 --> 06:22.740
Now it's going to have rigid body and hinge joint as well.

06:22.740 --> 06:24.330
Then we're going to go to base.

06:24.330 --> 06:29.040
And as a hinge joint over here as a connected rigid body we're going to choose chain.

06:29.460 --> 06:33.570
Then we're going to select chain and drag chain one to this field.

06:34.120 --> 06:40.090
Then chain one going to be connected with the chain two and chain two going to be connected with a spiked

06:40.090 --> 06:40.990
ball.

06:41.560 --> 06:45.610
And now when you go to play mode you'll see that all of them are connected.

06:46.830 --> 06:48.360
And it swings like that.

06:50.460 --> 06:52.710
And I really like how it looks.

06:53.380 --> 06:55.480
So that's all what we need to do now.

06:55.480 --> 06:58.090
We have a dangerous trap that moves left and right.

06:58.570 --> 06:59.830
Yeah, so that's good.

06:59.830 --> 07:03.880
If you want to make it longer, then you need to add more chains and connect them.

07:03.880 --> 07:06.490
Other than that, I think that's all what we need to do.

07:06.490 --> 07:10.690
Let's go to prefab make it as a prefab GameObject.

07:10.690 --> 07:14.470
And now we can take it, place it somewhere else if you want.

07:14.470 --> 07:20.050
Maybe here you can change push force for this object like maybe uh minus ten.

07:20.050 --> 07:23.560
So it's going to be pushed to the left and that's it.

07:25.820 --> 07:27.830
Now we have a dangerous level.

07:28.770 --> 07:30.780
That is not very easy to beat.

07:38.660 --> 07:40.250
Need to wait for the soul.

07:41.330 --> 07:42.920
Then need to jump here.

07:42.920 --> 07:44.660
Wait for the swing trap.

07:44.660 --> 07:45.860
Take the banana.

07:46.310 --> 07:48.170
Jump, jump, jump.

07:49.350 --> 07:51.030
And a very cool one.

07:51.030 --> 07:51.780
Love it.

07:51.810 --> 07:54.240
Okay, see you in the next video.
