Let's add more traps in our game to do that.
I'm gonna head over to my project app assets and then sprites folder, then Pixel Adventure folder,
then free folder and then traps.
And I'm gonna find spike.
Head over here.
I have as you can notice.
So let's select that sprite.
Go over to Inspector and let's click on this Open Sprite editor.
So we need to slice individually.
So let's choose pixel per unit to 16, sprite mode to multiple and filter mode to point of filter.
And let's click on this apply button and let's go over to Inspector sorry.
Let's go over to Sprite Editor tab.
Instead of slicing automatic we're gonna slice individually.
So let's click on this slice.
Let's choose automatic to create pixel count.
And let's also we have four columns.
So we're gonna put four columns and one row.
Let's click on slice and then click on this apply button in sprite Editor and I'm going to select my
game view.
Once again let's click on this arrow and let's select the first one.
And let's drag it into the scene view.
Or you can simply drag it into the hierarchy as well.
I'm going to drag it into my scene view.
As you can see.
And let's select the move tool in the scene view.
And let's move it uh, somewhere around here.
And I want this spike to move between two points as we, uh, just, uh, have done this.
So game object.
And before that, we're going to add some components to this spike game object for collision detection.
And we need to, uh, we need to assign this spike hat to something.
Drop game object.
Basically this is a trap.
So that's why we're gonna assign with trap.
Uh, basically we're gonna assign with the tag called trap that we already created as we assign it inside
this game object.
So let's firstly rename this to something like a spike hat.
So let's select that in a hierarchy.
Then go over to Inspector.
And we're going to call it something spike hat.
Let's call that.
And let's add some components to this game object.
First thing I'm going to add a rigid body 2D.
And I will set it gravity scale to zero.
So it's not going to fall down at all.
So let's click on this add component.
And we're going to add a rigid body 2D uh by typing let's uh add that up.
So type that and it's going to pop up.
So sorry little bit.
And let's add that and let's go over to Gravity scale I'm going to set back to zero.
Basically I'm going to set to zero.
So it's not going to fall down at all.
And collision detection we're going to choose continuous and interpolate to.
We're going to choose interpolate to making out smooth.
Or you can just skip this part.
And let's add one more component for collision Lesion detection.
So let's click on this add component.
And we can simply add a box Collider 2D.
But Box Collider 2D is not gonna be fine since as you can see there is a triangular shape.
Basically we need to make our collider the sprite size.
So that's why.
So for this we're going to add a Polygon Collider 2D.
And it's going to be perfect.
So let's click on this add component.
And let's find Polygon Collider 2D by typing.
And let's add that up.
And let's click on this Edit Collider and edit the Collider as the size of your sprite.
Like this.
As you can notice.
So I hope you get the idea that how you can add the collider and make sure the collider basically fits
perfectly to your sprite, and this seems pretty much cool.
And we can just do we can just go ahead and let's basically adjust the collider.
Sorry.
I'm gonna add the collider like this.
And this seems pretty much fine.
Two two.
Two.
And if you've done anything wrong, then you can simply press down Control Plus Z on your keyboard to
undo anything like that.
To undo.
And we are done.
As you can see now, it's perfectly fit.
So once we are done, we can just click on this polygon Collider 2D and the Inspector in order to collapse.
And let's assign this game object as a drop tag, as we have done inside this game object.
So let's select this spike hat.
Let's go over to Inspector and let's check with our trap as well as we're gonna layer the define as.
Sorry, we don't have the layer for it, so we're just going to leave as a trap.
Tag means this.
This is our trap and what we need to do now we're going to make the animation.
So to make the animation let's go over to that sprite sheet.
Let's click on this arrow.
Let's choose the individual all of them by holding down shift.
And let's drag it over top of this spike head GameObject in the hierarchy in order to make the animation.
So we will go to assets in the top left assets and then animation.
Other animation.
Sorry, not other animation.
Basically we're going to move over to traps animation folder and we have to name this animation.
So this animation will be running of this spike ahead.
So we're going to call this like spike head as we have done with the game object.
So we're going to call it simply spike head.
Spike head cat animation, let's call it something like that.
Underscore animation, something like that.
It's totally up to you what you want to call it or what you just want to name it.
And after doing that, let's click on the save button.
And if we select spike head in the hierarchy then go over to animation tab and animation tab.
And then click on this play button.
As you can see, it's playing the animation clip which is just blinking the eye as you can notice.
So this seems pretty much cool.
And we what we want to do, we just want to move this spike between two points.
So what we're going to do we're going to create some points for this spike ahead.
But before we do we're going to attach the script uh, in in our this spike spike head game object.
So we can select our spike head game object.
Then go over to Inspector, click on Add Component and we're going to add the script inside this spike
head game object as well.
And if you want, you can just create a separate escape something for your spike head.
But I'm going to use a I'm going to reuse that, uh, scratch script to move this spike head game object
so we can simply select our spike head GameObject in the hierarchy.
Then go over to Inspector, click on Add Component, and we can find the component by typing the name
of the component.
And we looking for.
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
order to attach or what else you can do.
You can simply more uh, simply move over to your project app assets and then scrape folder where you
have the script, then select that and then drag it over to add component section and Inspector.
So I'm not going to do that since I already attached as you can notice.
And now we need to put some points in order to move our spike head.
So let's create some points for this spike head.
To do that, I'm going to hop.
I'm going to move over to my hierarchy.
Let's create an empty parent GameObject first.
And inside that GameObject, we're just going to create the points that where we just want to move,
which point between we just want to move our spike head game object.
Uh, but before we do, let's make this spike head game object a prefab.
So we will have the copy, and we don't need to work from scratch or start over.
So let's select our spike head GameObject in the hierarchy, and let's drag it over to this prefabs
folder in our project tab.
Now as you can see, we just turned it into a prefab.
And let's create those points.
So let's go to hierarchy.
Right click or hit this plus icon.
Then click click on that plus icon.
Let's create an empty parent game object or empty game object.
And let's call this a game object to something like spike head points, something like that.
So let's call it spike hat.
Hat point something like that.
And then go over to Inspector.
Right click on this transform and then reset.
And if you want to choose an icon just click over here.
And I'm going to choose this green.
And we can see that right over here.
Now what we're going to do I'm going to take my spike head head points game object.
And I'm going to drag it in the top of my hierarchy so I can see all the time.
So let's select our spike head game head points game object.
Now let's right click on it.
And let's create an empty game object.
And we're going to call this game object to something like one.
Or you can simply call it a first point.
So I'm going to select that one.
And let's select the move tool in the scene view.
And let's move it somewhere over here.
And if you're not able to see then you can choose an icon or guest post for it.
To do that, let's click on this box in the Inspector and let's choose this green one, something like
that.
And let's duplicate this point in order to make a duplicate of it, because we're going to have two
points and this spike head just going to move over between two points.
So let's select our one game object or the first one.
Let's press down control D by selecting it in order to duplicate.
And let's let's move it duplicate somewhere around here.
And let's call this one to something like two or second point.
Now as you can see we just created.
So now what we can do we can select our spike head GameObject in the hierarchy.
Then go over to uh go over to Inspector.
And we need to drag the points one by one and to make it better, basically to have it in a better way.
What you can do, you can just lock the inspector.
So firstly select your spike head GameObject in the hierarchy.
Then go over to Inspector.
In the top right you can see the lock button, so just click on it.
And now if we select any other game object we can see the inspector is locked.
So now what we can do.
We can select the first point and the second point by holding down shift or holding down control.
And we can just simply drag it over to this points array.
As you can see we just drag it.
And now our game object just gonna move between these two points.
And you will notice that firstly it's gonna move over to this point because we in the start of the game
in inside our start function, we just pass the point index zero and and zero basically means the first
point.
So that's why this spike head game object just gonna move over to this first point.
And also make sure you just unlock the inspector.
So go over to Inspector one more time.
In the top right you can see the lock button, a lock icon, so just click on it in order to unlock.
Now as you can notice, we just unlock and we can just go over to hierarchy.
Then spike points game object.
Let's click over here in order to collapse.
And now it seems pretty much fine.
And if we just go ahead and then click on this play button in the top you will see the spike head game
object.
Just gonna move between these two points.
Firstly it's gonna move over to first point and then it's gonna move over to second point.
So just wait a minute and you will see.
And we also need to create some other traps.
It's going to be fire and some other traps.
So just wait a moment.
And once we are done with this spike head, then we can just go ahead and we can create other traps.
And now you will see that.
So indeed we can see it's moving to the first point and then it's moved over to the second point, as
you can notice.
And it just just moving between these two points.
And as you know we can create as many points we want and we can just move over to move over this spike
head game object to that point basically the third or fourth point as well.
So I hope you get the idea.
And we just need to move over.
Basically, we need to move our spike head game object a little bit down.
So simply we can select these two points and we can just simply move it a little bit down.
So this spike head game object just gonna move just gonna move close to our ground.
So let's get out of play mode and we're gonna move over to Spike Head Points GameObject in the hierarchy.
Then click here and we're going to select first and the second point by holding down shift.
And let's move it a little bit down or what?
Simply we can do for now.
We can just move this spike head game object somewhere.
Uh, somewhere around here.
Let's do it.
Sorry.
Uh, we're gonna move this one here.
So let's select these two points by holding down shift, and we're gonna move it, uh, somewhere around.
We need to find a perfect place over here.
Something like that.
And I'm going to, uh, make the, uh, make the point something over here.
Then let's select this one and let's do that.
And now we're going to select our spike head GameObject in the hierarchy.
And let's press down F in order to focus on it.
And we also gonna move this, uh, spike game object for now.
Uh, over to those, uh, points, uh, something over here.
And now we gonna notice that this spike head game object is just going to move between this point and
between this spike head points.
So if we just go ahead and then click on this play button in the top in order to play our game, you
will notice that as soon as our game just gonna start, you will notice our spike Head game object.
Just going to move between those two points which we recently created.
And we just drag it into that array.
But and we can create as many points we want as well.
So as you can notice indeed it's doing.
But as you can see it's basically rotating in the z axis.
And we need to stop doing that.
To do that, we're going to get out of play mode and we will select our spike head GameObject in the
hierarchy.
Then go over to Inspector.
Inspector then rigid body 2D.
Then you need to move over to this constraint.
So click there and then click on this trace the z rotation.
And now if we just go ahead and then click on this play button in the top.
You will notice this spike head game object is not gonna rotate like that.
Rotate like that as a as a as you seen it's rotating now it's not rotate because basically we just freeze
the rotation about z axis.
So as you can notice by now we can see it's not rotating.
But as something feels awkward basically we can check that it's just colliding with this crown.
And we don't want to do that.
What we're going to do, we're going to get out of play mode.
And we need to, uh, we need to move our spike head game object a little bit up.
So it's not going to collide with this crowd, and it's not gonna do that weird thing.
So we can simply select our those two points and let's bring it a little bit up, something like that.
And we're going to select our spike head game object as well.
Let's move it a little bit up.
So it's not going to collide with this ground.
And it's not gonna do the weird thing.
So now if we go add and then click on this play button.
It's gonna be fine by now.
And we also need to create some other animation, other traps like fire traps we're gonna have, we're
gonna have, uh, a shuriken, which just going to be still at one point, uh, just gonna stick at
one point.
As you can notice by now, it seems perfect and it's not colliding with this ground game object anymore.
So I hope you get the idea that how you can do it.
So I'm gonna get out of play mode.