In this lecture, we're adding an enemy into our game.
We're going to set up all the components.
We're going to add the animation from the sprites that we chopped up earlier and just have him standing
on the spot bouncing around.
Two quick notes before I start.
I've added a little bit more flavor to my level, just so I've got some room to have our enemy running
around in and I've moved my player down to here.
Also, I added the no friction physics material to to our box collider to our feet, basically, because
I found a couple of times my player was getting stuck in certain areas, so just needed to add that
same material with no friction to his feet.
Now let's turn our attention enemies.
If I click on sprites previously we brought in our enemies, so that was from one of the previous lectures
in this section, if you like.
Where are the enemies?
Go find that from previous lecture.
But what we did is chop that up.
We've got our one, two, three, four, five, six sprites in here of our enemy bouncing along.
Look at him.
Cute little purple guy there.
So what we're going to do is create an enemy.
Now, if you want to do this as a race, the race is that we can see who's first to set up the enemy
to add all the components we need, to add collider's, rigid body, all that kind of stuff, and to
get the enemy just sitting on the spot animating.
So sitting there and just doing, going through these animations, not moving left and right yet, just
sitting there doing the animating.
So if you want to have a little bit of a race with this, that could be a little bit of fun.
So I'm going to start by right clicking in the hierarchy.
I will create a 2D object, I'll create an empty game object.
I will call this goober and init and just kind of be just saying goober.
I don't know why, but Goober and we'll call them the enemy because we might have other enemies, so
we'll call him better than just enemy.
Right?
Click on the Transform Reset so that our enemy is reset on one of those criteria.
But now I will go and drag it down here next to the player.
So when it appears, I know it'll be there.
Next up, we're going to add some components.
First of all, we need the Sprite renderer.
Where's the Sprite renderer?
There we go.
Sprite renderer.
I'm going to pop in one of these frames just as the let's see, enemy, just to be the visualization
of our enemy.
Now it's going to be sitting in who knows where now sort of cause default.
I'm going to add a new sort layer.
So going to add layers, going to sorting layers, I'll click on plus make this one the enemies and
then enter back over to GBA and we will find our sorting layers.
Changes to enemies.
There we go.
Enemy appears nice.
What we should do actually for a bit of due diligence we're going to add layer and then sorting layers.
We'll make sure this is in the right order.
So that means the enemies will appear over the top of the player that we want, that I might actually
say the player is always going to be on the top of everything just in case, but we might want to switch
that around later on if we find there's some weirdness.
Next up, I'm going to add component and this will be a rigid body, 2d, you need one of those instead
of body type being dynamic will change this kinematic because we're not using the physics system to
bounce off walls and stuff.
We're saying move to the right, move to the left, and that is kinematic.
Well, we're moving the object, but not really worrying about the physics system to help us out with
that movement.
Next, I'm going to add a capsule.
Collider Sure.
Collider How are you going?
We're still doing a race here, enjoying the race, making some good progress.
We've got our enemy.
I'm going to click on the edit collider just to make sure it represents mostly where the enemy is.
Woop see, I often do that.
Well, that's going to give you a lead in our little race here, but uncoordinated with this.
Okay, zoom in a little bit more.
Maybe that's it.
Click on the green dot, click on the green dot, click on the green dot.
And you can see the whole thing is a little bit too high.
So I can change the offset on the Y axis just to drag it down a little bit.
Okay.
What's next in our little racing?
We need an animator, so we'll need to animate a component because we need to play through our frames
that we've got next.
We need an animator controller.
So jump over in here.
We've got the player animator controller showing.
I'm going to go in animations, right click create animator controller and we'll name this goober just
in case we've got a bunch of different enemies.
So we've got Goober who's an enemy.
We've got this in here.
There's nothing in there at the moment.
So what we need to do is get some animations, click back over onto our sprites, find the six frames,
highlight those right click, create animation.
Excellent.
Where's our animation gone?
There it is.
Just a new atom there.
I'll rename this to be Goober Anim.
Okay, now grab the goober and drop it into our animator controller.
There's our one animation.
We'd be a little bit more detailed with this if there was more than one animation.
We don't need to do any transitions because it's just going just into that.
That's all it's doing.
Now.
We need to go back to our animated control.
We actually go back to Goober, the enemy.
We find our animator.
We need to say which animator controller we're looking for.
So next to controller, click our select us like Goober and then click on play and see if that has worked.
See if we've got him standing on the spot doing his little jig.
No, it's stopping.
Why is that?
Okay, we haven't set up our animation properly, so I need to click on our goober anim and find loop
time.
Yes, loop time.
That means Goober should go through and through through his animation.
We'll see that if it cycles through here.
There we go.
Is bouncing, bouncing, bouncing.
He's a little bit high up in there.
He's not kind of bouncing, which is what I was expecting.
And I think that might have to do with our Sprite.
So let's go all the way back to our sprites.
Look at the Sprite sheet, click on the Sprite editor you can.
See.
Let's see.
Boom, boom, boom, boom.
That should be up in the air a little bit there, shouldn't it?
It looks like he's going up and then down.
But what's going on here is that our we've got a bit of space between where we think it should be and
where it actually is.
So I'm going to grab the blue line, click on each of these, grab the blue line, just put it right
at the bottom.
So Juba's going to be flying along on the ground.
That I think is the better way to do this and that one there.
We will leave it at the same level as all the others.
So we want a little bit of space.
So he does fly happily up in the air.
Flying in the air, the dirt.
There we go.
Well, apply that that should work at the very least that he'll be bouncing on the ground instead of
floating in the air.
Not entirely.
It could be because our game object is just floating off the ground.
Okay, so there we go.
There's a lesson in that.
Just move your game object into the correct position.
Boiling Point only is doing a little bit of a jump.
Okay.
I think that's all we need to do for now.
I just wanted to get Goober in there all set up with the different components and doing its base animation
so that in the next lecture we can get him moving left and right.
So I'll see you in the next lecture.