1
00:00:00,000 --> 00:00:03,600
Welcome back my fellow game developers to

2
00:00:03,600 --> 00:00:09,150
a brand new video where we will be adding animations to our enemy.

3
00:00:09,150 --> 00:00:10,950
Look, he is idling.

4
00:00:10,950 --> 00:00:12,180
I am idling.

5
00:00:12,180 --> 00:00:16,170
If I get close enough and notice that he's looking my way.

6
00:00:16,170 --> 00:00:18,270
If I get close enough, There you go.

7
00:00:18,270 --> 00:00:19,910
You can see he starts walking,

8
00:00:19,905 --> 00:00:21,435
starts trying to kill me.

9
00:00:21,435 --> 00:00:23,075
I can still push him back.

10
00:00:23,070 --> 00:00:26,010
I run away. He stands there. I run away.

11
00:00:26,010 --> 00:00:26,810
He stops.

12
00:00:26,805 --> 00:00:28,875
He starts eye-opening. I get close.

13
00:00:28,875 --> 00:00:30,495
He started teaching. I can shoot him.

14
00:00:30,495 --> 00:00:31,935
He doesn't feel anything.

15
00:00:31,930 --> 00:00:39,860
Okay, so let's stop wasting time and let's get started in animating our enemies.

16
00:00:39,860 --> 00:00:41,600
0 case.

17
00:00:41,600 --> 00:00:45,100
So let's get to animating our enemy.

18
00:00:45,095 --> 00:00:49,955
So if we go into the sprites and to the enemies,

19
00:00:49,955 --> 00:00:52,825
the monster, Monsters, and you have

20
00:00:52,820 --> 00:00:56,240
the skeleton and you have all these different sprites.

21
00:00:56,240 --> 00:01:01,580
So what I'm going to do is I am going to go ahead and dissect all of these.

22
00:01:01,580 --> 00:01:06,380
And I'm just going to show you how I'm going to do this animation differently.

23
00:01:06,380 --> 00:01:08,390
And then you are going to do

24
00:01:08,390 --> 00:01:11,790
all the rest because you already know how to create animations.

25
00:01:11,794 --> 00:01:14,374
Now, the only difference this time,

26
00:01:14,375 --> 00:01:19,505
As I'm going to go ahead and do the animations immediately on the body.

27
00:01:19,505 --> 00:01:23,875
And I'm going to then access the animator from the enemy script writing.

28
00:01:23,870 --> 00:01:26,530
We're going to access the animator on the body.

29
00:01:26,525 --> 00:01:27,745
Why?

30
00:01:27,740 --> 00:01:31,160
Well, honestly, it's always better to use

31
00:01:31,160 --> 00:01:34,520
the animations and create them the way we did with the doom player.

32
00:01:34,520 --> 00:01:39,620
But for one, I think a change of the way we create things will give

33
00:01:39,620 --> 00:01:44,840
you a better perspective and a broader understanding of how things work.

34
00:01:44,840 --> 00:01:48,590
Plus, we get the chance to use a new method,

35
00:01:48,590 --> 00:01:50,990
which is get the component and child,

36
00:01:50,990 --> 00:01:56,360
which I would like to show you all the methods that are possible and just like that.

37
00:01:56,360 --> 00:01:59,210
So let's go ahead and add a component and then you

38
00:01:59,210 --> 00:02:02,590
can choose which is the better way for you.

39
00:02:02,585 --> 00:02:04,705
Whereas the animation window,

40
00:02:04,700 --> 00:02:06,350
okay, let's go to Windows.

41
00:02:06,350 --> 00:02:11,230
So maybe when we change the layout, the animation disappeared.

42
00:02:11,225 --> 00:02:14,095
I'm going to set the animation right here.

43
00:02:14,090 --> 00:02:19,630
I'm going to go ahead and create an animation on the body of the enemy.

44
00:02:19,625 --> 00:02:25,865
So create and the enemies assets animations,

45
00:02:25,865 --> 00:02:31,445
right-click, create the skeleton and animations.

46
00:02:31,445 --> 00:02:34,325
This will be the skeleton.

47
00:02:34,325 --> 00:02:38,465
Skeleton idling.

48
00:02:38,465 --> 00:02:39,805
Save that.

49
00:02:39,800 --> 00:02:44,020
I'm going to choose the idling.

50
00:02:44,015 --> 00:02:47,795
Where is it? I will choose all of those,

51
00:02:47,795 --> 00:02:48,905
drag them in here.

52
00:02:48,905 --> 00:02:50,215
So now when we run,

53
00:02:50,210 --> 00:02:53,170
you can see he is idling really fast.

54
00:02:53,165 --> 00:02:56,505
He's extremely excited to be idling.

55
00:02:56,509 --> 00:02:58,399
I'm going to move those.

56
00:02:58,400 --> 00:03:00,310
Let's see how that looks.

57
00:03:00,305 --> 00:03:03,095
And for some reason.

58
00:03:03,095 --> 00:03:04,495
So I think the first,

59
00:03:04,490 --> 00:03:06,800
second 1 are the same.

60
00:03:06,800 --> 00:03:10,880
And why is that? It's that.

61
00:03:10,880 --> 00:03:14,420
So let's run. No, wait.

62
00:03:14,420 --> 00:03:16,690
Oh, okay, so the first,

63
00:03:16,690 --> 00:03:20,720
second 1 for some reason that I not choose the Swan.

64
00:03:20,720 --> 00:03:23,000
No worries. Let's go ahead and do this.

65
00:03:23,000 --> 00:03:24,530
Okay, great.

66
00:03:24,530 --> 00:03:32,650
So you can see the last one is already similar to the first one. Or no.

67
00:03:32,645 --> 00:03:34,595
Let's copy this.

68
00:03:34,595 --> 00:03:37,555
Set it as the last one. See how that looks.

69
00:03:37,550 --> 00:03:40,640
Yep, there we go. This looks much better.

70
00:03:40,640 --> 00:03:42,860
Should we make it faster? I don't know.

71
00:03:42,860 --> 00:03:45,280
But we're going to save this.

72
00:03:45,275 --> 00:03:47,225
And this one is the entry.

73
00:03:47,225 --> 00:03:50,635
So I just wanted to show you how we're doing this.

74
00:03:50,630 --> 00:03:55,520
We are going to continue and I've written skeleton wrong, no worries about that.

75
00:03:55,520 --> 00:03:59,900
And we are going to continue this way on the body.

76
00:03:59,900 --> 00:04:05,110
And then I'm going to use the magic of editing to do all of this in a couple of seconds.

77
00:04:05,105 --> 00:04:06,925
But you take your time,

78
00:04:06,920 --> 00:04:10,050
create the animation slice of the sprites.

79
00:04:10,054 --> 00:04:14,994
And I'm was going to show you a challenge which is to choose one of the enemies.

80
00:04:14,990 --> 00:04:16,400
It doesn't have to be the skeleton.

81
00:04:16,400 --> 00:04:20,020
So create the ICD-10 walking attack.

82
00:04:20,015 --> 00:04:25,285
You have the attack of throwing a soul and you have the sword throwing animation.

83
00:04:25,280 --> 00:04:28,490
So I believe there is a sword throwing animation.

84
00:04:28,490 --> 00:04:30,920
So pause the video right now.

85
00:04:30,920 --> 00:04:33,670
Slugs up the sprites, create the animations.

86
00:04:33,665 --> 00:04:35,485
I'll see you in just a bit.

87
00:04:35,480 --> 00:04:39,710
Hey, how did you get on with that?

88
00:04:39,710 --> 00:04:42,160
So I've been slicing up sprites.

89
00:04:42,155 --> 00:04:44,095
I've been creating animations.

90
00:04:44,090 --> 00:04:45,950
Let me show you what I did.

91
00:04:45,950 --> 00:04:47,690
If I click on the enemy,

92
00:04:47,690 --> 00:04:48,800
on the body, you,

93
00:04:48,800 --> 00:04:50,710
you can see that I have idling,

94
00:04:50,705 --> 00:04:53,485
attacking, walking and throwing the sort.

95
00:04:53,480 --> 00:04:56,440
So I throw the sword, just like that.

96
00:04:56,435 --> 00:04:59,425
I attack this guy.

97
00:04:59,420 --> 00:05:02,230
Running and walking pretty easy.

98
00:05:02,225 --> 00:05:03,385
That's how I did everything.

99
00:05:03,380 --> 00:05:05,570
I hope it wasn't too hard for you.

100
00:05:05,570 --> 00:05:10,340
I hope you made sure that all of them were 150 by 150.

101
00:05:10,340 --> 00:05:13,850
So you can see all the slices need to be exactly the

102
00:05:13,850 --> 00:05:17,510
same just like I told you when we were slicing to doom play.

103
00:05:17,510 --> 00:05:21,530
Okay, and let me show you the animator so you can see that I have

104
00:05:21,530 --> 00:05:25,570
all of those four now we are not going to be doing anything.

105
00:05:25,565 --> 00:05:29,945
We are not going to be thrown the salt or the skeleton attacking will keep that for.

106
00:05:29,945 --> 00:05:32,635
Later on, we will be walking.

107
00:05:32,630 --> 00:05:37,660
So I'm going to create a transition from the skeleton walking to the skeleton idling.

108
00:05:37,655 --> 00:05:42,035
I'm going to choose both of those by holding Control, choosing both.

109
00:05:42,035 --> 00:05:44,515
Remove on the exit time on both,

110
00:05:44,510 --> 00:05:47,890
remove the transition duration on both.

111
00:05:47,885 --> 00:05:52,915
I'm going to create a parameter in here that's going to be called as walking.

112
00:05:52,910 --> 00:05:54,110
So it's the same.

113
00:05:54,110 --> 00:05:57,350
Oh, no, wait, I created the wrong parameter.

114
00:05:57,350 --> 00:05:59,030
I created a layer.

115
00:05:59,030 --> 00:06:04,220
I'm going to create a Boolean parameter here is walking.

116
00:06:04,220 --> 00:06:07,760
There you go, and I'm going to stay.

117
00:06:07,760 --> 00:06:09,800
Okay, so I'm in this transition,

118
00:06:09,799 --> 00:06:12,859
I am going to add the parameters in here.

119
00:06:12,860 --> 00:06:15,980
So if I am walking is true,

120
00:06:15,980 --> 00:06:18,720
we start walking and walking,

121
00:06:18,724 --> 00:06:20,284
false, I stop walking.

122
00:06:20,285 --> 00:06:21,835
Say all of that.

123
00:06:21,830 --> 00:06:27,050
Now, let's go back to our scene and let's open up our scripts in here.

124
00:06:27,050 --> 00:06:28,700
So what should we be doing?

125
00:06:28,700 --> 00:06:31,790
The first thing we need is a reference to the animator.

126
00:06:31,789 --> 00:06:34,369
So in the enemy controller right here,

127
00:06:34,370 --> 00:06:39,590
I'm going to create a private and it's going to be the enemy.

128
00:06:39,590 --> 00:06:42,160
And he made toward that,

129
00:06:42,155 --> 00:06:45,005
oops, it's of type animator.

130
00:06:45,005 --> 00:06:48,035
And he may, toward save that.

131
00:06:48,035 --> 00:06:50,015
I'm going to get the component.

132
00:06:50,015 --> 00:06:52,415
But as you saw,

133
00:06:52,415 --> 00:06:55,835
the animator isn't actually on the enemy,

134
00:06:55,835 --> 00:06:57,335
so I cannot access it.

135
00:06:57,335 --> 00:06:59,845
When I, as we've said, Get component,

136
00:06:59,840 --> 00:07:04,570
the components should be on the same object as the script.

137
00:07:04,565 --> 00:07:06,085
So to fix this,

138
00:07:06,080 --> 00:07:10,150
I'm going to have to access the animator on the body.

139
00:07:10,145 --> 00:07:14,495
To do that. I'm simply going to say that the animator,

140
00:07:14,495 --> 00:07:17,645
I mean the enemy animator,

141
00:07:17,645 --> 00:07:21,665
is equal to get component in children.

142
00:07:21,665 --> 00:07:23,405
And you can see right now,

143
00:07:23,405 --> 00:07:26,435
let me just finish this off.

144
00:07:26,435 --> 00:07:28,495
Let's hover over it.

145
00:07:28,490 --> 00:07:30,400
Okay, so there is no explanation,

146
00:07:30,395 --> 00:07:35,305
but I think it's pretty self-explanatory get component just like this one,

147
00:07:35,300 --> 00:07:38,720
but in children, so we find the animator in the children,

148
00:07:38,720 --> 00:07:42,160
and because we only have one animator, that's no problem.

149
00:07:42,155 --> 00:07:44,285
But we use this carefully.

150
00:07:44,285 --> 00:07:46,525
So next thing we're going to do,

151
00:07:46,520 --> 00:07:50,060
we're going to check for when we add a velocity.

152
00:07:50,060 --> 00:07:54,890
So in here, we're going to check if the direction to move

153
00:07:54,890 --> 00:08:01,010
and is different than vector to the 0 or vector 3,

154
00:08:01,010 --> 00:08:02,440
excuse me, because this one,

155
00:08:02,435 --> 00:08:03,905
I remember it was a factor three.

156
00:08:03,905 --> 00:08:05,225
Oh, there you go.

157
00:08:05,225 --> 00:08:06,845
How did that autocomplete?

158
00:08:06,845 --> 00:08:08,035
I don't even know.

159
00:08:08,030 --> 00:08:13,910
I'm going to access the enemy animator dot set Bool.

160
00:08:13,910 --> 00:08:16,490
So this is extremely easy.

161
00:08:16,490 --> 00:08:19,000
I believe we've all ready done this.

162
00:08:18,995 --> 00:08:22,855
So you just get a small peak at the behind the scenes.

163
00:08:22,850 --> 00:08:27,430
Copy this, paste it in here,

164
00:08:27,425 --> 00:08:30,235
and we're going to set it to true.

165
00:08:30,230 --> 00:08:33,680
Then else statement.

166
00:08:33,680 --> 00:08:38,030
We are going to duplicate this line for it in

167
00:08:38,030 --> 00:08:43,300
here and set it to false and remove the extra white-space.

168
00:08:43,295 --> 00:08:44,545
So what happens in here?

169
00:08:44,540 --> 00:08:46,840
As soon as we have direction to move in,

170
00:08:46,835 --> 00:08:49,675
it's different than vector 3 0.

171
00:08:49,670 --> 00:08:53,410
The animation is walking is set to true and we transition to the animation.

172
00:08:53,405 --> 00:08:55,525
If we're not walking, it's false.

173
00:08:55,520 --> 00:08:59,180
Okay, great. Let's test this out back in our game.

174
00:08:59,180 --> 00:09:00,770
Let's put the animator.

175
00:09:00,770 --> 00:09:02,990
Where should we put them all? Let's keep him in here.

176
00:09:02,990 --> 00:09:06,870
Game, run the game. Let's see.

177
00:09:06,865 --> 00:09:09,435
Okay, so the enemy is idling.

178
00:09:09,430 --> 00:09:11,320
If I get close to him,

179
00:09:11,320 --> 00:09:13,120
he will start walking.

180
00:09:13,120 --> 00:09:16,280
And there you go. You can see that he is walking,

181
00:09:16,284 --> 00:09:18,084
but there is a slight problem.

182
00:09:18,085 --> 00:09:20,935
I feel as if there is something.

183
00:09:20,935 --> 00:09:23,785
Okay. So he is hovering a little bit.

184
00:09:23,785 --> 00:09:25,665
Why is he still hovering,

185
00:09:25,660 --> 00:09:26,860
did we not okay.

186
00:09:26,860 --> 00:09:31,800
So obviously we did not remove the transition time from this one.

187
00:09:31,795 --> 00:09:36,915
Run the game again, he should start walking immediately as soon as he starts moving.

188
00:09:36,910 --> 00:09:39,690
There you go. He is walking towards us.

189
00:09:39,685 --> 00:09:40,455
Excellent.

190
00:09:40,450 --> 00:09:44,140
Now, one more thing that we need to take arrow and

191
00:09:44,140 --> 00:09:48,090
that is the direction the enemy is looking at.

192
00:09:48,090 --> 00:09:52,930
So I'm going to do a similar thing, just like here.

193
00:09:52,925 --> 00:09:58,375
If the mouse position not acts just like way we flipped our player,

194
00:09:58,370 --> 00:10:00,590
we are going to flip our enemy.

195
00:10:00,590 --> 00:10:02,870
But instead of looking on the screen point,

196
00:10:02,870 --> 00:10:08,980
we are going to compare the direction or the x of the player to the acts of the enemy.

197
00:10:08,975 --> 00:10:13,685
So if the layer to chase dot,

198
00:10:13,685 --> 00:10:20,205
the player to chase dot position,

199
00:10:20,209 --> 00:10:27,009
dot x is less than the transform.py position x.

200
00:10:27,005 --> 00:10:33,905
What we're going to do is we're going to access the transform local scale.

201
00:10:33,905 --> 00:10:42,775
And it's going to be equal to a new vector 3 and minus1 f. What's that?

202
00:10:42,770 --> 00:10:47,510
Minus1 f. And we'll keep the y the same.

203
00:10:47,510 --> 00:10:50,880
And the z, Z,

204
00:10:50,880 --> 00:10:54,260
z, Z, whatever you wanna call it, the same.

205
00:10:54,260 --> 00:10:58,220
And else, if the player is on the other side,

206
00:10:58,220 --> 00:11:07,170
the transform local scale is equal to a new vector, three dot one.

207
00:11:07,690 --> 00:11:10,580
If I'm not mistaken, No.1,

208
00:11:10,580 --> 00:11:13,900
one, what's the problem? Vector 3.

209
00:11:13,895 --> 00:11:17,555
Okay. So I shouldn't put, let me see.

210
00:11:17,555 --> 00:11:20,245
Okay, so no new, excuse me.

211
00:11:20,240 --> 00:11:23,560
So whenever we're not creating a new vector 1,

212
00:11:23,555 --> 00:11:25,765
we just have a vector one that we're setting

213
00:11:25,760 --> 00:11:29,660
the local scale to save that back in our game.

214
00:11:29,660 --> 00:11:31,760
Let's see this in action.

215
00:11:31,760 --> 00:11:35,270
Run the game. And there you go.

216
00:11:35,270 --> 00:11:37,770
You can see that he is looking in the right direction.

217
00:11:37,774 --> 00:11:38,964
As soon as we come close,

218
00:11:38,960 --> 00:11:41,240
he starts walking towards us. Okay, Great.

219
00:11:41,240 --> 00:11:42,340
I tried to run away.

220
00:11:42,335 --> 00:11:44,965
He looks at us and he keeps chasing.

221
00:11:44,960 --> 00:11:48,200
Now the only problem I noticed is that

222
00:11:48,200 --> 00:11:53,080
the enemy is hitting the walls or just like we have the problem previously.

223
00:11:53,075 --> 00:11:56,695
Remember when we wanted to have the enemies.

224
00:11:56,690 --> 00:11:59,960
So you can see because of the collider on the enemy,

225
00:11:59,960 --> 00:12:05,290
he cannot move past this wall right here you can see these are his limitations.

226
00:12:05,285 --> 00:12:08,485
If you want to make your game more detailed,

227
00:12:08,480 --> 00:12:11,390
I do recommend that you add two colliders,

228
00:12:11,390 --> 00:12:13,480
just like we did on the doom Player.

229
00:12:13,475 --> 00:12:15,265
One of them will be just to get heard.

230
00:12:15,260 --> 00:12:18,020
The second one will just be where we walk.

231
00:12:18,020 --> 00:12:19,480
Where is our limitation?

232
00:12:19,475 --> 00:12:20,735
Feel free to do that.

233
00:12:20,735 --> 00:12:23,575
I encourage you to do that. This is your game.

234
00:12:23,570 --> 00:12:26,260
You can make it as perfect as you want.

235
00:12:26,255 --> 00:12:31,615
With that done, we are going to obviously set everything in here.

236
00:12:31,610 --> 00:12:34,240
You can see how many animations I've created.

237
00:12:34,235 --> 00:12:35,755
I hope you enjoy it.

238
00:12:35,750 --> 00:12:37,910
I'll stage all of that and I'll see you in

239
00:12:37,910 --> 00:12:42,200
the next video where we will be actually damaging our enemy.

240
00:12:42,200 --> 00:12:43,760
We can currently shoot him,

241
00:12:43,760 --> 00:12:45,680
but he doesn't feel anything.

242
00:12:45,680 --> 00:12:48,190
That's what we're going to fix in the future.

243
00:12:48,185 --> 00:12:51,145
And I do recommend that you also create the animation

244
00:12:51,140 --> 00:12:54,040
for the ticket and the animation for the Deaf,

245
00:12:54,035 --> 00:12:58,055
which will be very fun to do next video.

246
00:12:58,055 --> 00:13:00,155
So I'll see you then.

