WEBVTT

00:00.080 --> 00:04.000
Let's add more traps in our game to do that.

00:04.040 --> 00:10.520
I'm gonna head over to my project app assets and then sprites folder, then Pixel Adventure folder,

00:10.560 --> 00:12.920
then free folder and then traps.

00:12.920 --> 00:14.880
And I'm gonna find spike.

00:14.880 --> 00:16.080
Head over here.

00:16.080 --> 00:18.080
I have as you can notice.

00:18.080 --> 00:19.640
So let's select that sprite.

00:19.680 --> 00:24.160
Go over to Inspector and let's click on this Open Sprite editor.

00:24.160 --> 00:26.200
So we need to slice individually.

00:26.280 --> 00:33.560
So let's choose pixel per unit to 16, sprite mode to multiple and filter mode to point of filter.

00:33.720 --> 00:39.840
And let's click on this apply button and let's go over to Inspector sorry.

00:39.880 --> 00:42.400
Let's go over to Sprite Editor tab.

00:42.560 --> 00:46.360
Instead of slicing automatic we're gonna slice individually.

00:46.360 --> 00:47.840
So let's click on this slice.

00:47.840 --> 00:50.800
Let's choose automatic to create pixel count.

00:51.000 --> 00:53.920
And let's also we have four columns.

00:53.920 --> 00:56.280
So we're gonna put four columns and one row.

00:56.320 --> 01:02.420
Let's click on slice and then click on this apply button in sprite Editor and I'm going to select my

01:02.420 --> 01:02.900
game view.

01:02.940 --> 01:06.900
Once again let's click on this arrow and let's select the first one.

01:06.900 --> 01:09.060
And let's drag it into the scene view.

01:09.100 --> 01:12.700
Or you can simply drag it into the hierarchy as well.

01:12.740 --> 01:15.020
I'm going to drag it into my scene view.

01:15.060 --> 01:16.140
As you can see.

01:16.300 --> 01:18.980
And let's select the move tool in the scene view.

01:18.980 --> 01:22.340
And let's move it uh, somewhere around here.

01:22.540 --> 01:29.020
And I want this spike to move between two points as we, uh, just, uh, have done this.

01:29.020 --> 01:30.060
So game object.

01:30.180 --> 01:36.460
And before that, we're going to add some components to this spike game object for collision detection.

01:36.460 --> 01:42.260
And we need to, uh, we need to assign this spike hat to something.

01:42.300 --> 01:43.460
Drop game object.

01:43.500 --> 01:45.060
Basically this is a trap.

01:45.060 --> 01:47.380
So that's why we're gonna assign with trap.

01:47.580 --> 01:54.740
Uh, basically we're gonna assign with the tag called trap that we already created as we assign it inside

01:54.740 --> 01:56.380
this game object.

01:56.380 --> 02:00.240
So let's firstly rename this to something like a spike hat.

02:00.240 --> 02:02.400
So let's select that in a hierarchy.

02:02.440 --> 02:03.920
Then go over to Inspector.

02:03.920 --> 02:07.240
And we're going to call it something spike hat.

02:07.400 --> 02:08.680
Let's call that.

02:08.680 --> 02:11.720
And let's add some components to this game object.

02:11.720 --> 02:14.240
First thing I'm going to add a rigid body 2D.

02:14.240 --> 02:17.000
And I will set it gravity scale to zero.

02:17.000 --> 02:19.320
So it's not going to fall down at all.

02:19.320 --> 02:21.480
So let's click on this add component.

02:21.880 --> 02:29.040
And we're going to add a rigid body 2D uh by typing let's uh add that up.

02:29.360 --> 02:31.840
So type that and it's going to pop up.

02:31.840 --> 02:33.280
So sorry little bit.

02:33.280 --> 02:38.520
And let's add that and let's go over to Gravity scale I'm going to set back to zero.

02:38.680 --> 02:40.240
Basically I'm going to set to zero.

02:40.240 --> 02:42.680
So it's not going to fall down at all.

02:42.680 --> 02:46.640
And collision detection we're going to choose continuous and interpolate to.

02:46.680 --> 02:49.880
We're going to choose interpolate to making out smooth.

02:49.920 --> 02:52.040
Or you can just skip this part.

02:52.200 --> 02:55.740
And let's add one more component for collision Lesion detection.

02:55.740 --> 02:57.900
So let's click on this add component.

02:57.900 --> 03:00.700
And we can simply add a box Collider 2D.

03:00.740 --> 03:08.380
But Box Collider 2D is not gonna be fine since as you can see there is a triangular shape.

03:08.500 --> 03:12.700
Basically we need to make our collider the sprite size.

03:12.700 --> 03:13.580
So that's why.

03:13.740 --> 03:17.020
So for this we're going to add a Polygon Collider 2D.

03:17.020 --> 03:18.820
And it's going to be perfect.

03:18.820 --> 03:21.100
So let's click on this add component.

03:21.100 --> 03:24.340
And let's find Polygon Collider 2D by typing.

03:24.620 --> 03:26.300
And let's add that up.

03:26.620 --> 03:32.060
And let's click on this Edit Collider and edit the Collider as the size of your sprite.

03:32.060 --> 03:32.900
Like this.

03:33.140 --> 03:34.580
As you can notice.

03:34.740 --> 03:41.580
So I hope you get the idea that how you can add the collider and make sure the collider basically fits

03:41.580 --> 03:46.900
perfectly to your sprite, and this seems pretty much cool.

03:47.820 --> 03:55.080
And we can just do we can just go ahead and let's basically adjust the collider.

03:55.440 --> 03:56.000
Sorry.

03:57.920 --> 04:01.000
I'm gonna add the collider like this.

04:04.080 --> 04:06.880
And this seems pretty much fine.

04:12.360 --> 04:12.720
Two two.

04:12.800 --> 04:12.960
Two.

04:13.000 --> 04:13.160
Two.

04:13.200 --> 04:13.400
Two.

04:13.400 --> 04:13.560
Two.

04:13.760 --> 04:20.040
And if you've done anything wrong, then you can simply press down Control Plus Z on your keyboard to

04:20.080 --> 04:22.240
undo anything like that.

04:22.240 --> 04:23.000
To undo.

04:23.840 --> 04:26.360
And we are done.

04:26.600 --> 04:29.240
As you can see now, it's perfectly fit.

04:29.520 --> 04:37.280
So once we are done, we can just click on this polygon Collider 2D and the Inspector in order to collapse.

04:37.280 --> 04:43.960
And let's assign this game object as a drop tag, as we have done inside this game object.

04:44.040 --> 04:45.960
So let's select this spike hat.

04:46.000 --> 04:53.290
Let's go over to Inspector and let's check with our trap as well as we're gonna layer the define as.

04:53.650 --> 04:58.370
Sorry, we don't have the layer for it, so we're just going to leave as a trap.

04:58.370 --> 04:59.850
Tag means this.

04:59.970 --> 05:05.730
This is our trap and what we need to do now we're going to make the animation.

05:05.730 --> 05:08.850
So to make the animation let's go over to that sprite sheet.

05:08.890 --> 05:10.370
Let's click on this arrow.

05:10.410 --> 05:14.290
Let's choose the individual all of them by holding down shift.

05:14.290 --> 05:21.290
And let's drag it over top of this spike head GameObject in the hierarchy in order to make the animation.

05:21.290 --> 05:26.250
So we will go to assets in the top left assets and then animation.

05:26.570 --> 05:27.570
Other animation.

05:27.570 --> 05:29.130
Sorry, not other animation.

05:29.130 --> 05:35.130
Basically we're going to move over to traps animation folder and we have to name this animation.

05:35.130 --> 05:39.010
So this animation will be running of this spike ahead.

05:39.250 --> 05:45.170
So we're going to call this like spike head as we have done with the game object.

05:45.170 --> 05:48.330
So we're going to call it simply spike head.

05:49.050 --> 05:51.990
Spike head cat animation, let's call it something like that.

05:51.990 --> 05:54.870
Underscore animation, something like that.

05:54.910 --> 06:00.190
It's totally up to you what you want to call it or what you just want to name it.

06:00.190 --> 06:03.030
And after doing that, let's click on the save button.

06:03.270 --> 06:09.990
And if we select spike head in the hierarchy then go over to animation tab and animation tab.

06:09.990 --> 06:11.710
And then click on this play button.

06:11.710 --> 06:18.510
As you can see, it's playing the animation clip which is just blinking the eye as you can notice.

06:18.510 --> 06:20.270
So this seems pretty much cool.

06:20.270 --> 06:26.950
And we what we want to do, we just want to move this spike between two points.

06:27.430 --> 06:32.270
So what we're going to do we're going to create some points for this spike ahead.

06:32.310 --> 06:39.830
But before we do we're going to attach the script uh, in in our this spike spike head game object.

06:39.830 --> 06:42.750
So we can select our spike head game object.

06:42.750 --> 06:49.050
Then go over to Inspector, click on Add Component and we're going to add the script inside this spike

06:49.050 --> 06:50.770
head game object as well.

06:50.970 --> 06:56.690
And if you want, you can just create a separate escape something for your spike head.

06:56.730 --> 07:05.090
But I'm going to use a I'm going to reuse that, uh, scratch script to move this spike head game object

07:05.090 --> 07:09.010
so we can simply select our spike head GameObject in the hierarchy.

07:09.210 --> 07:14.490
Then go over to Inspector, click on Add Component, and we can find the component by typing the name

07:14.490 --> 07:15.330
of the component.

07:15.330 --> 07:16.690
And we looking for.

07:16.730 --> 07:23.490
So as you can see, as soon as we type it just pop up and we can just click on this, click on it in

07:23.490 --> 07:26.010
order to attach or what else you can do.

07:26.010 --> 07:32.530
You can simply more uh, simply move over to your project app assets and then scrape folder where you

07:32.530 --> 07:38.250
have the script, then select that and then drag it over to add component section and Inspector.

07:38.250 --> 07:42.570
So I'm not going to do that since I already attached as you can notice.

07:42.810 --> 07:47.550
And now we need to put some points in order to move our spike head.

07:47.710 --> 07:51.510
So let's create some points for this spike head.

07:51.550 --> 07:53.110
To do that, I'm going to hop.

07:53.150 --> 07:55.110
I'm going to move over to my hierarchy.

07:55.150 --> 07:57.950
Let's create an empty parent GameObject first.

07:58.070 --> 08:05.110
And inside that GameObject, we're just going to create the points that where we just want to move,

08:05.750 --> 08:10.910
which point between we just want to move our spike head game object.

08:11.430 --> 08:15.990
Uh, but before we do, let's make this spike head game object a prefab.

08:15.990 --> 08:21.270
So we will have the copy, and we don't need to work from scratch or start over.

08:21.470 --> 08:27.270
So let's select our spike head GameObject in the hierarchy, and let's drag it over to this prefabs

08:27.270 --> 08:29.390
folder in our project tab.

08:29.510 --> 08:32.790
Now as you can see, we just turned it into a prefab.

08:33.350 --> 08:35.350
And let's create those points.

08:35.390 --> 08:36.870
So let's go to hierarchy.

08:36.910 --> 08:39.030
Right click or hit this plus icon.

08:39.270 --> 08:41.390
Then click click on that plus icon.

08:41.390 --> 08:45.410
Let's create an empty parent game object or empty game object.

08:45.410 --> 08:50.850
And let's call this a game object to something like spike head points, something like that.

08:50.850 --> 08:53.570
So let's call it spike hat.

08:54.010 --> 08:56.330
Hat point something like that.

08:56.610 --> 08:58.330
And then go over to Inspector.

08:58.330 --> 09:01.090
Right click on this transform and then reset.

09:01.090 --> 09:05.450
And if you want to choose an icon just click over here.

09:05.450 --> 09:07.210
And I'm going to choose this green.

09:07.210 --> 09:09.810
And we can see that right over here.

09:09.810 --> 09:14.610
Now what we're going to do I'm going to take my spike head head points game object.

09:14.610 --> 09:19.330
And I'm going to drag it in the top of my hierarchy so I can see all the time.

09:19.690 --> 09:23.450
So let's select our spike head game head points game object.

09:23.490 --> 09:25.370
Now let's right click on it.

09:25.370 --> 09:27.850
And let's create an empty game object.

09:27.850 --> 09:30.730
And we're going to call this game object to something like one.

09:30.730 --> 09:33.730
Or you can simply call it a first point.

09:33.730 --> 09:35.410
So I'm going to select that one.

09:35.410 --> 09:37.850
And let's select the move tool in the scene view.

09:37.850 --> 09:40.370
And let's move it somewhere over here.

09:40.570 --> 09:45.630
And if you're not able to see then you can choose an icon or guest post for it.

09:45.630 --> 09:52.030
To do that, let's click on this box in the Inspector and let's choose this green one, something like

09:52.030 --> 09:52.430
that.

09:52.590 --> 09:59.110
And let's duplicate this point in order to make a duplicate of it, because we're going to have two

09:59.110 --> 10:03.910
points and this spike head just going to move over between two points.

10:04.150 --> 10:07.430
So let's select our one game object or the first one.

10:07.430 --> 10:11.710
Let's press down control D by selecting it in order to duplicate.

10:11.750 --> 10:16.470
And let's let's move it duplicate somewhere around here.

10:16.710 --> 10:20.670
And let's call this one to something like two or second point.

10:20.910 --> 10:23.390
Now as you can see we just created.

10:23.390 --> 10:27.830
So now what we can do we can select our spike head GameObject in the hierarchy.

10:28.110 --> 10:30.790
Then go over to uh go over to Inspector.

10:30.990 --> 10:38.790
And we need to drag the points one by one and to make it better, basically to have it in a better way.

10:38.990 --> 10:41.930
What you can do, you can just lock the inspector.

10:41.930 --> 10:45.330
So firstly select your spike head GameObject in the hierarchy.

10:45.490 --> 10:47.010
Then go over to Inspector.

10:47.010 --> 10:50.530
In the top right you can see the lock button, so just click on it.

10:50.530 --> 10:55.370
And now if we select any other game object we can see the inspector is locked.

10:55.850 --> 10:57.330
So now what we can do.

10:57.370 --> 11:03.410
We can select the first point and the second point by holding down shift or holding down control.

11:03.410 --> 11:06.730
And we can just simply drag it over to this points array.

11:06.970 --> 11:08.930
As you can see we just drag it.

11:08.930 --> 11:13.010
And now our game object just gonna move between these two points.

11:13.210 --> 11:19.490
And you will notice that firstly it's gonna move over to this point because we in the start of the game

11:19.890 --> 11:26.450
in inside our start function, we just pass the point index zero and and zero basically means the first

11:26.450 --> 11:27.010
point.

11:27.010 --> 11:31.890
So that's why this spike head game object just gonna move over to this first point.

11:32.090 --> 11:35.090
And also make sure you just unlock the inspector.

11:35.090 --> 11:37.170
So go over to Inspector one more time.

11:37.170 --> 11:43.590
In the top right you can see the lock button, a lock icon, so just click on it in order to unlock.

11:43.630 --> 11:48.470
Now as you can notice, we just unlock and we can just go over to hierarchy.

11:48.510 --> 11:51.070
Then spike points game object.

11:51.110 --> 11:53.670
Let's click over here in order to collapse.

11:53.790 --> 11:55.790
And now it seems pretty much fine.

11:56.030 --> 12:02.630
And if we just go ahead and then click on this play button in the top you will see the spike head game

12:02.670 --> 12:02.990
object.

12:02.990 --> 12:05.390
Just gonna move between these two points.

12:06.510 --> 12:11.830
Firstly it's gonna move over to first point and then it's gonna move over to second point.

12:11.830 --> 12:14.070
So just wait a minute and you will see.

12:16.670 --> 12:20.190
And we also need to create some other traps.

12:20.470 --> 12:23.830
It's going to be fire and some other traps.

12:23.830 --> 12:25.190
So just wait a moment.

12:25.510 --> 12:32.910
And once we are done with this spike head, then we can just go ahead and we can create other traps.

12:33.910 --> 12:36.350
And now you will see that.

12:36.790 --> 12:43.130
So indeed we can see it's moving to the first point and then it's moved over to the second point, as

12:43.130 --> 12:44.130
you can notice.

12:44.130 --> 12:47.850
And it just just moving between these two points.

12:48.010 --> 12:57.090
And as you know we can create as many points we want and we can just move over to move over this spike

12:57.090 --> 13:02.170
head game object to that point basically the third or fourth point as well.

13:02.170 --> 13:03.970
So I hope you get the idea.

13:03.970 --> 13:05.970
And we just need to move over.

13:06.370 --> 13:10.690
Basically, we need to move our spike head game object a little bit down.

13:10.690 --> 13:16.610
So simply we can select these two points and we can just simply move it a little bit down.

13:16.610 --> 13:22.810
So this spike head game object just gonna move just gonna move close to our ground.

13:22.810 --> 13:28.730
So let's get out of play mode and we're gonna move over to Spike Head Points GameObject in the hierarchy.

13:28.770 --> 13:33.130
Then click here and we're going to select first and the second point by holding down shift.

13:33.250 --> 13:36.500
And let's move it a little bit down or what?

13:36.540 --> 13:38.380
Simply we can do for now.

13:38.380 --> 13:42.780
We can just move this spike head game object somewhere.

13:44.540 --> 13:46.820
Uh, somewhere around here.

13:48.100 --> 13:50.300
Uh, somewhere around here.

13:52.340 --> 13:53.580
Let's do it.

13:53.580 --> 13:54.100
Sorry.

13:55.020 --> 13:57.260
Uh, we're gonna move this one here.

13:57.260 --> 14:05.140
So let's select these two points by holding down shift, and we're gonna move it, uh, somewhere around.

14:07.820 --> 14:11.260
We need to find a perfect place over here.

14:11.260 --> 14:12.420
Something like that.

14:12.780 --> 14:18.540
And I'm going to, uh, make the, uh, make the point something over here.

14:18.900 --> 14:22.620
Then let's select this one and let's do that.

14:22.620 --> 14:26.060
And now we're going to select our spike head GameObject in the hierarchy.

14:26.260 --> 14:29.180
And let's press down F in order to focus on it.

14:29.180 --> 14:32.980
And we also gonna move this, uh, spike game object for now.

14:33.420 --> 14:39.600
Uh, over to those, uh, points, uh, something over here.

14:39.840 --> 14:46.800
And now we gonna notice that this spike head game object is just going to move between this point and

14:46.840 --> 14:49.080
between this spike head points.

14:49.080 --> 14:55.120
So if we just go ahead and then click on this play button in the top in order to play our game, you

14:55.120 --> 15:01.880
will notice that as soon as our game just gonna start, you will notice our spike Head game object.

15:02.200 --> 15:07.120
Just going to move between those two points which we recently created.

15:07.120 --> 15:09.600
And we just drag it into that array.

15:09.800 --> 15:13.880
But and we can create as many points we want as well.

15:13.880 --> 15:16.560
So as you can notice indeed it's doing.

15:16.720 --> 15:23.360
But as you can see it's basically rotating in the z axis.

15:23.560 --> 15:25.800
And we need to stop doing that.

15:25.800 --> 15:31.080
To do that, we're going to get out of play mode and we will select our spike head GameObject in the

15:31.080 --> 15:31.680
hierarchy.

15:31.900 --> 15:33.460
Then go over to Inspector.

15:34.020 --> 15:36.140
Inspector then rigid body 2D.

15:36.380 --> 15:38.980
Then you need to move over to this constraint.

15:38.980 --> 15:43.300
So click there and then click on this trace the z rotation.

15:43.300 --> 15:47.580
And now if we just go ahead and then click on this play button in the top.

15:47.700 --> 15:52.860
You will notice this spike head game object is not gonna rotate like that.

15:53.620 --> 16:03.860
Rotate like that as a as a as you seen it's rotating now it's not rotate because basically we just freeze

16:03.860 --> 16:06.300
the rotation about z axis.

16:06.580 --> 16:11.060
So as you can notice by now we can see it's not rotating.

16:11.060 --> 16:19.140
But as something feels awkward basically we can check that it's just colliding with this crown.

16:19.300 --> 16:21.780
And we don't want to do that.

16:21.780 --> 16:24.220
What we're going to do, we're going to get out of play mode.

16:24.220 --> 16:29.740
And we need to, uh, we need to move our spike head game object a little bit up.

16:29.840 --> 16:35.640
So it's not going to collide with this crowd, and it's not gonna do that weird thing.

16:36.040 --> 16:42.680
So we can simply select our those two points and let's bring it a little bit up, something like that.

16:42.840 --> 16:46.320
And we're going to select our spike head game object as well.

16:46.320 --> 16:48.160
Let's move it a little bit up.

16:48.160 --> 16:51.000
So it's not going to collide with this ground.

16:51.000 --> 16:53.480
And it's not gonna do the weird thing.

16:53.720 --> 16:57.040
So now if we go add and then click on this play button.

16:57.040 --> 16:58.960
It's gonna be fine by now.

16:59.600 --> 17:07.240
And we also need to create some other animation, other traps like fire traps we're gonna have, we're

17:07.240 --> 17:15.280
gonna have, uh, a shuriken, which just going to be still at one point, uh, just gonna stick at

17:15.280 --> 17:15.920
one point.

17:15.920 --> 17:23.680
As you can notice by now, it seems perfect and it's not colliding with this ground game object anymore.

17:23.680 --> 17:26.600
So I hope you get the idea that how you can do it.

17:26.800 --> 17:29.120
So I'm gonna get out of play mode.
