1
00:00:03,070 --> 00:00:05,380
In this lecture, we're adding an enemy into our game.

2
00:00:05,380 --> 00:00:06,790
We're going to set up all the components.

3
00:00:06,790 --> 00:00:11,440
We're going to add the animation from the sprites that we chopped up earlier and just have him standing

4
00:00:11,440 --> 00:00:12,980
on the spot bouncing around.

5
00:00:13,000 --> 00:00:14,620
Two quick notes before I start.

6
00:00:14,620 --> 00:00:18,970
I've added a little bit more flavor to my level, just so I've got some room to have our enemy running

7
00:00:18,970 --> 00:00:21,010
around in and I've moved my player down to here.

8
00:00:21,010 --> 00:00:27,370
Also, I added the no friction physics material to to our box collider to our feet, basically, because

9
00:00:27,370 --> 00:00:31,870
I found a couple of times my player was getting stuck in certain areas, so just needed to add that

10
00:00:31,870 --> 00:00:34,250
same material with no friction to his feet.

11
00:00:34,270 --> 00:00:35,740
Now let's turn our attention enemies.

12
00:00:35,740 --> 00:00:40,360
If I click on sprites previously we brought in our enemies, so that was from one of the previous lectures

13
00:00:40,360 --> 00:00:41,260
in this section, if you like.

14
00:00:41,260 --> 00:00:42,070
Where are the enemies?

15
00:00:42,070 --> 00:00:44,290
Go find that from previous lecture.

16
00:00:44,290 --> 00:00:46,000
But what we did is chop that up.

17
00:00:46,000 --> 00:00:50,530
We've got our one, two, three, four, five, six sprites in here of our enemy bouncing along.

18
00:00:50,530 --> 00:00:50,890
Look at him.

19
00:00:50,890 --> 00:00:52,270
Cute little purple guy there.

20
00:00:52,270 --> 00:00:53,920
So what we're going to do is create an enemy.

21
00:00:53,920 --> 00:00:59,290
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

22
00:00:59,290 --> 00:01:04,330
to add all the components we need, to add collider's, rigid body, all that kind of stuff, and to

23
00:01:04,330 --> 00:01:07,690
get the enemy just sitting on the spot animating.

24
00:01:07,690 --> 00:01:11,860
So sitting there and just doing, going through these animations, not moving left and right yet, just

25
00:01:11,860 --> 00:01:12,820
sitting there doing the animating.

26
00:01:12,820 --> 00:01:15,340
So if you want to have a little bit of a race with this, that could be a little bit of fun.

27
00:01:15,340 --> 00:01:18,220
So I'm going to start by right clicking in the hierarchy.

28
00:01:18,220 --> 00:01:22,210
I will create a 2D object, I'll create an empty game object.

29
00:01:22,210 --> 00:01:27,370
I will call this goober and init and just kind of be just saying goober.

30
00:01:27,370 --> 00:01:31,420
I don't know why, but Goober and we'll call them the enemy because we might have other enemies, so

31
00:01:31,420 --> 00:01:33,130
we'll call him better than just enemy.

32
00:01:33,130 --> 00:01:33,580
Right?

33
00:01:33,580 --> 00:01:37,750
Click on the Transform Reset so that our enemy is reset on one of those criteria.

34
00:01:37,750 --> 00:01:40,600
But now I will go and drag it down here next to the player.

35
00:01:40,600 --> 00:01:42,520
So when it appears, I know it'll be there.

36
00:01:42,520 --> 00:01:43,930
Next up, we're going to add some components.

37
00:01:43,930 --> 00:01:45,940
First of all, we need the Sprite renderer.

38
00:01:45,940 --> 00:01:46,810
Where's the Sprite renderer?

39
00:01:46,810 --> 00:01:47,410
There we go.

40
00:01:47,410 --> 00:01:48,040
Sprite renderer.

41
00:01:48,040 --> 00:01:55,060
I'm going to pop in one of these frames just as the let's see, enemy, just to be the visualization

42
00:01:55,060 --> 00:01:55,870
of our enemy.

43
00:01:55,870 --> 00:02:00,100
Now it's going to be sitting in who knows where now sort of cause default.

44
00:02:00,100 --> 00:02:01,630
I'm going to add a new sort layer.

45
00:02:01,780 --> 00:02:08,590
So going to add layers, going to sorting layers, I'll click on plus make this one the enemies and

46
00:02:08,590 --> 00:02:13,300
then enter back over to GBA and we will find our sorting layers.

47
00:02:13,300 --> 00:02:14,410
Changes to enemies.

48
00:02:14,410 --> 00:02:14,920
There we go.

49
00:02:14,920 --> 00:02:16,270
Enemy appears nice.

50
00:02:16,390 --> 00:02:21,130
What we should do actually for a bit of due diligence we're going to add layer and then sorting layers.

51
00:02:21,130 --> 00:02:22,540
We'll make sure this is in the right order.

52
00:02:22,540 --> 00:02:26,860
So that means the enemies will appear over the top of the player that we want, that I might actually

53
00:02:26,860 --> 00:02:31,180
say the player is always going to be on the top of everything just in case, but we might want to switch

54
00:02:31,180 --> 00:02:33,070
that around later on if we find there's some weirdness.

55
00:02:33,100 --> 00:02:38,860
Next up, I'm going to add component and this will be a rigid body, 2d, you need one of those instead

56
00:02:38,860 --> 00:02:43,930
of body type being dynamic will change this kinematic because we're not using the physics system to

57
00:02:43,930 --> 00:02:45,040
bounce off walls and stuff.

58
00:02:45,040 --> 00:02:47,980
We're saying move to the right, move to the left, and that is kinematic.

59
00:02:47,980 --> 00:02:51,880
Well, we're moving the object, but not really worrying about the physics system to help us out with

60
00:02:51,880 --> 00:02:52,600
that movement.

61
00:02:52,600 --> 00:02:54,190
Next, I'm going to add a capsule.

62
00:02:54,190 --> 00:02:55,390
Collider Sure.

63
00:02:55,390 --> 00:02:56,380
Collider How are you going?

64
00:02:56,380 --> 00:03:00,130
We're still doing a race here, enjoying the race, making some good progress.

65
00:03:00,130 --> 00:03:01,210
We've got our enemy.

66
00:03:01,210 --> 00:03:05,980
I'm going to click on the edit collider just to make sure it represents mostly where the enemy is.

67
00:03:05,980 --> 00:03:08,020
Woop see, I often do that.

68
00:03:08,350 --> 00:03:12,010
Well, that's going to give you a lead in our little race here, but uncoordinated with this.

69
00:03:12,010 --> 00:03:13,120
Okay, zoom in a little bit more.

70
00:03:13,120 --> 00:03:13,660
Maybe that's it.

71
00:03:13,660 --> 00:03:17,650
Click on the green dot, click on the green dot, click on the green dot.

72
00:03:17,650 --> 00:03:19,930
And you can see the whole thing is a little bit too high.

73
00:03:19,960 --> 00:03:25,090
So I can change the offset on the Y axis just to drag it down a little bit.

74
00:03:25,090 --> 00:03:25,360
Okay.

75
00:03:25,360 --> 00:03:26,550
What's next in our little racing?

76
00:03:26,560 --> 00:03:31,150
We need an animator, so we'll need to animate a component because we need to play through our frames

77
00:03:31,150 --> 00:03:32,080
that we've got next.

78
00:03:32,080 --> 00:03:33,850
We need an animator controller.

79
00:03:33,850 --> 00:03:34,600
So jump over in here.

80
00:03:34,600 --> 00:03:36,730
We've got the player animator controller showing.

81
00:03:36,730 --> 00:03:43,840
I'm going to go in animations, right click create animator controller and we'll name this goober just

82
00:03:43,840 --> 00:03:45,430
in case we've got a bunch of different enemies.

83
00:03:45,430 --> 00:03:47,170
So we've got Goober who's an enemy.

84
00:03:47,200 --> 00:03:48,250
We've got this in here.

85
00:03:48,250 --> 00:03:49,570
There's nothing in there at the moment.

86
00:03:49,570 --> 00:03:54,130
So what we need to do is get some animations, click back over onto our sprites, find the six frames,

87
00:03:54,130 --> 00:03:58,120
highlight those right click, create animation.

88
00:03:58,180 --> 00:03:58,870
Excellent.

89
00:03:58,870 --> 00:04:00,190
Where's our animation gone?

90
00:04:00,190 --> 00:04:00,580
There it is.

91
00:04:00,580 --> 00:04:01,720
Just a new atom there.

92
00:04:01,720 --> 00:04:05,020
I'll rename this to be Goober Anim.

93
00:04:05,020 --> 00:04:08,530
Okay, now grab the goober and drop it into our animator controller.

94
00:04:08,530 --> 00:04:09,850
There's our one animation.

95
00:04:09,850 --> 00:04:12,940
We'd be a little bit more detailed with this if there was more than one animation.

96
00:04:12,940 --> 00:04:16,149
We don't need to do any transitions because it's just going just into that.

97
00:04:16,149 --> 00:04:17,019
That's all it's doing.

98
00:04:17,019 --> 00:04:17,200
Now.

99
00:04:17,200 --> 00:04:19,420
We need to go back to our animated control.

100
00:04:19,420 --> 00:04:21,130
We actually go back to Goober, the enemy.

101
00:04:21,130 --> 00:04:22,840
We find our animator.

102
00:04:22,840 --> 00:04:25,270
We need to say which animator controller we're looking for.

103
00:04:25,270 --> 00:04:31,180
So next to controller, click our select us like Goober and then click on play and see if that has worked.

104
00:04:31,180 --> 00:04:34,620
See if we've got him standing on the spot doing his little jig.

105
00:04:34,720 --> 00:04:36,070
No, it's stopping.

106
00:04:36,070 --> 00:04:36,550
Why is that?

107
00:04:36,550 --> 00:04:42,100
Okay, we haven't set up our animation properly, so I need to click on our goober anim and find loop

108
00:04:42,100 --> 00:04:42,400
time.

109
00:04:42,400 --> 00:04:43,180
Yes, loop time.

110
00:04:43,180 --> 00:04:46,750
That means Goober should go through and through through his animation.

111
00:04:46,750 --> 00:04:49,030
We'll see that if it cycles through here.

112
00:04:49,060 --> 00:04:49,810
There we go.

113
00:04:49,840 --> 00:04:51,220
Is bouncing, bouncing, bouncing.

114
00:04:51,220 --> 00:04:52,360
He's a little bit high up in there.

115
00:04:52,360 --> 00:04:54,730
He's not kind of bouncing, which is what I was expecting.

116
00:04:54,730 --> 00:04:57,070
And I think that might have to do with our Sprite.

117
00:04:57,070 --> 00:04:59,010
So let's go all the way back to our sprites.

118
00:04:59,020 --> 00:05:02,260
Look at the Sprite sheet, click on the Sprite editor you can.

119
00:05:02,400 --> 00:05:03,000
See.

120
00:05:03,000 --> 00:05:03,620
Let's see.

121
00:05:03,630 --> 00:05:04,610
Boom, boom, boom, boom.

122
00:05:04,650 --> 00:05:06,560
That should be up in the air a little bit there, shouldn't it?

123
00:05:06,570 --> 00:05:08,370
It looks like he's going up and then down.

124
00:05:08,370 --> 00:05:15,000
But what's going on here is that our we've got a bit of space between where we think it should be and

125
00:05:15,000 --> 00:05:15,660
where it actually is.

126
00:05:15,660 --> 00:05:19,320
So I'm going to grab the blue line, click on each of these, grab the blue line, just put it right

127
00:05:19,320 --> 00:05:20,010
at the bottom.

128
00:05:20,010 --> 00:05:22,740
So Juba's going to be flying along on the ground.

129
00:05:22,980 --> 00:05:25,590
That I think is the better way to do this and that one there.

130
00:05:25,590 --> 00:05:28,170
We will leave it at the same level as all the others.

131
00:05:28,170 --> 00:05:29,430
So we want a little bit of space.

132
00:05:29,430 --> 00:05:31,590
So he does fly happily up in the air.

133
00:05:32,190 --> 00:05:33,510
Flying in the air, the dirt.

134
00:05:33,660 --> 00:05:34,380
There we go.

135
00:05:34,380 --> 00:05:39,060
Well, apply that that should work at the very least that he'll be bouncing on the ground instead of

136
00:05:39,060 --> 00:05:40,290
floating in the air.

137
00:05:41,700 --> 00:05:42,620
Not entirely.

138
00:05:42,630 --> 00:05:45,690
It could be because our game object is just floating off the ground.

139
00:05:45,720 --> 00:05:47,280
Okay, so there we go.

140
00:05:47,310 --> 00:05:48,120
There's a lesson in that.

141
00:05:48,120 --> 00:05:50,430
Just move your game object into the correct position.

142
00:05:50,430 --> 00:05:52,540
Boiling Point only is doing a little bit of a jump.

143
00:05:52,560 --> 00:05:52,860
Okay.

144
00:05:52,860 --> 00:05:54,090
I think that's all we need to do for now.

145
00:05:54,090 --> 00:05:58,950
I just wanted to get Goober in there all set up with the different components and doing its base animation

146
00:05:58,950 --> 00:06:02,310
so that in the next lecture we can get him moving left and right.

147
00:06:02,310 --> 00:06:03,720
So I'll see you in the next lecture.

