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

2
00:00:03,360 --> 00:00:04,950
to a brand new video.

3
00:00:04,950 --> 00:00:06,720
And in this one, as you can see,

4
00:00:06,720 --> 00:00:10,910
we've created a little flying freaking demon,

5
00:00:10,905 --> 00:00:14,825
but this time he is not a very brave.

6
00:00:14,820 --> 00:00:16,080
He is a bit cowardly,

7
00:00:16,080 --> 00:00:18,630
so he starts running away when we get close.

8
00:00:18,630 --> 00:00:20,360
So now I walk around,

9
00:00:20,355 --> 00:00:21,755
I get close and as you can see,

10
00:00:21,750 --> 00:00:25,170
he starts running away and throwing his poop at us,

11
00:00:25,170 --> 00:00:27,470
I think, or dirt or I don't know what that is.

12
00:00:27,465 --> 00:00:29,615
So as you can see, we tried to shoot him.

13
00:00:29,610 --> 00:00:32,040
We tried to get close, obviously his stock by the wall,

14
00:00:32,040 --> 00:00:33,320
but you can see that when we

15
00:00:33,320 --> 00:00:35,170
approach from a different direction,

16
00:00:35,165 --> 00:00:36,515
still his stock on the wall,

17
00:00:36,515 --> 00:00:37,855
but no worries about that.

18
00:00:37,850 --> 00:00:40,250
You see that he is running away from us.

19
00:00:40,250 --> 00:00:44,650
So let's not waste any more time and let's get started.

20
00:00:44,645 --> 00:00:47,755
Okay, so as you can see,

21
00:00:47,750 --> 00:00:50,510
I've created for more enemies,

22
00:00:50,510 --> 00:00:53,410
the cowardly flying, I,

23
00:00:53,405 --> 00:00:55,765
the goblin wonder one.

24
00:00:55,760 --> 00:00:58,300
I don't know why it's called Wonder one,

25
00:00:58,295 --> 00:01:00,055
but anyways, that's his name.

26
00:01:00,050 --> 00:01:01,940
And of course we have the skeleton and

27
00:01:01,940 --> 00:01:04,490
finally we have the patrolling mushroom.

28
00:01:04,490 --> 00:01:06,370
So we are going to be using

29
00:01:06,365 --> 00:01:08,185
all of these in every single video.

30
00:01:08,180 --> 00:01:09,920
And as I've said, I don't want to go

31
00:01:09,920 --> 00:01:12,070
through the process of doing this with you.

32
00:01:12,065 --> 00:01:15,085
All I did is I just duplicated the skeleton,

33
00:01:15,080 --> 00:01:17,290
change the body sprite,

34
00:01:17,285 --> 00:01:20,885
change the animator, the animation and all of that.

35
00:01:20,885 --> 00:01:22,915
I also made sure to change and here

36
00:01:22,910 --> 00:01:25,420
the animation and so on and so forth.

37
00:01:25,415 --> 00:01:28,415
So now they all chases and do the same.

38
00:01:28,415 --> 00:01:30,535
But what we're going to do is we're going to

39
00:01:30,530 --> 00:01:33,140
remove the cowardly or the goblin Wanderer,

40
00:01:33,140 --> 00:01:36,590
the patrolling mushroom, and the skeleton enemy.

41
00:01:36,590 --> 00:01:40,240
And we're just going to keep the cowardly flying I,

42
00:01:40,235 --> 00:01:44,045
and this is what we'll use to create our cowardly enemy.

43
00:01:44,045 --> 00:01:46,195
So without any further ado,

44
00:01:46,190 --> 00:01:48,500
let's go ahead and open up the control.

45
00:01:48,500 --> 00:01:50,500
Oh, and by the way, I've also created

46
00:01:50,495 --> 00:01:52,955
a projectile for each one of those.

47
00:01:52,955 --> 00:01:55,355
So each one has his own projectile.

48
00:01:55,355 --> 00:01:56,555
I've created that too.

49
00:01:56,555 --> 00:01:58,685
But anyways, and let's

50
00:01:58,685 --> 00:02:01,295
open up the enemy controller in here.

51
00:02:01,295 --> 00:02:04,145
And let's get started with a couple of goats.

52
00:02:04,145 --> 00:02:07,315
So the first thing that we need is we need to go up

53
00:02:07,310 --> 00:02:12,460
here and we'll need to add a bit of space.

54
00:02:12,455 --> 00:02:15,745
And we're going to say that these are the enemies that

55
00:02:15,740 --> 00:02:21,680
runaway and it means that run away.

56
00:02:21,680 --> 00:02:23,690
And in here I'm going to create

57
00:02:23,690 --> 00:02:26,080
two serialized fields which are going to be

58
00:02:26,075 --> 00:02:31,405
a Boolean for the should run away.

59
00:02:31,400 --> 00:02:34,220
And then another serialized field for

60
00:02:34,220 --> 00:02:38,740
the float run away range.

61
00:02:38,735 --> 00:02:42,005
So R1 way range.

62
00:02:42,005 --> 00:02:44,455
And obviously because we want to have

63
00:02:44,450 --> 00:02:46,060
a certain range at which

64
00:02:46,055 --> 00:02:48,635
the enemy will start running away.

65
00:02:48,635 --> 00:02:51,335
Now, there is another thing that we need to add

66
00:02:51,335 --> 00:02:54,235
because we are creating enemies that should run away.

67
00:02:54,230 --> 00:02:55,280
We also should know

68
00:02:55,280 --> 00:02:57,670
the enemies that should be chasing the player.

69
00:02:57,665 --> 00:03:00,905
So I'm going to again create another one in here,

70
00:03:00,905 --> 00:03:02,795
which is going to be the,

71
00:03:02,795 --> 00:03:06,335
or know what up here we've created something.

72
00:03:06,335 --> 00:03:08,545
And he made the attacker within the news that

73
00:03:08,540 --> 00:03:11,900
yet player move direction,

74
00:03:11,900 --> 00:03:14,300
player to chase player chase range.

75
00:03:14,300 --> 00:03:16,220
Okay, so in here I'm going to create

76
00:03:16,220 --> 00:03:19,790
this and have the enemies that chess player,

77
00:03:19,790 --> 00:03:23,980
enemies that chase the layer.

78
00:03:23,975 --> 00:03:26,365
And in here I'm also going to create

79
00:03:26,360 --> 00:03:29,180
a serialized field for the Boolean.

80
00:03:29,179 --> 00:03:35,469
There's going to be the should chase player.

81
00:03:35,465 --> 00:03:37,105
There we go. So now we have

82
00:03:37,100 --> 00:03:39,320
the option to choose one of these two.

83
00:03:39,320 --> 00:03:42,940
And let's see what we need to do before we continue on.

84
00:03:42,935 --> 00:03:46,065
We need to add this should chase player condition.

85
00:03:46,069 --> 00:03:47,539
So where do we add it?

86
00:03:47,540 --> 00:03:49,470
First of all, we need to add it obviously

87
00:03:49,474 --> 00:03:52,974
in when we are giving velocity.

88
00:03:52,970 --> 00:03:55,010
So in here we update

89
00:03:55,010 --> 00:03:58,310
looking animating enemy moving towards the player.

90
00:03:58,310 --> 00:04:00,670
So there we go, moving towards the player.

91
00:04:00,665 --> 00:04:03,685
And here we need to make sure that we are also

92
00:04:03,680 --> 00:04:08,420
having and we should chase the player.

93
00:04:08,420 --> 00:04:11,420
So in here we get the direction which is the player

94
00:04:11,420 --> 00:04:12,770
to chase position minus

95
00:04:12,770 --> 00:04:14,690
the current position of the enemy.

96
00:04:14,690 --> 00:04:17,570
And then we go there and we said the is chasing.

97
00:04:17,570 --> 00:04:19,070
And in here as you can see,

98
00:04:19,070 --> 00:04:20,990
I have redundant code.

99
00:04:20,990 --> 00:04:23,290
These two lines are exactly the same.

100
00:04:23,285 --> 00:04:25,195
So what I'm going to do is I'm

101
00:04:25,190 --> 00:04:27,160
going to create a variable in here,

102
00:04:27,155 --> 00:04:28,765
which is going to be called,

103
00:04:28,760 --> 00:04:32,080
so distance is a float.

104
00:04:32,075 --> 00:04:35,405
So we're going to create a float,

105
00:04:35,405 --> 00:04:38,875
which is going to be the distance,

106
00:04:38,870 --> 00:04:43,040
distance player, enemy.

107
00:04:43,040 --> 00:04:47,890
And it's going to be equal to the vector distance,

108
00:04:47,885 --> 00:04:49,685
et cetera, et cetera.

109
00:04:49,685 --> 00:04:51,845
And instead of this long line,

110
00:04:51,845 --> 00:04:55,975
I'm going to say that it's the distance layer enemy.

111
00:04:55,970 --> 00:04:58,280
Add a bit of space.

112
00:04:58,280 --> 00:05:01,630
There we go. And now double-click in here,

113
00:05:01,625 --> 00:05:04,255
copy that, paste it in here it's the same, right?

114
00:05:04,250 --> 00:05:06,170
So transform position, player

115
00:05:06,170 --> 00:05:08,410
chase dot position, exactly the same.

116
00:05:08,405 --> 00:05:09,295
There we go.

117
00:05:09,290 --> 00:05:10,330
We save that.

118
00:05:10,325 --> 00:05:13,075
And also in here we need to make sure that he is

119
00:05:13,070 --> 00:05:18,650
chasing and is the should chase player.

120
00:05:18,650 --> 00:05:20,950
There we go, save that.

121
00:05:20,945 --> 00:05:22,135
And with that done,

122
00:05:22,130 --> 00:05:24,460
let's continue on and see what we have.

123
00:05:24,455 --> 00:05:25,925
Now in here.

124
00:05:25,925 --> 00:05:27,865
We already know what happens

125
00:05:27,860 --> 00:05:29,840
if we should be chasing the player.

126
00:05:29,840 --> 00:05:31,430
But what happens if we should

127
00:05:31,430 --> 00:05:33,220
be running away from the player?

128
00:05:33,215 --> 00:05:36,425
I'm going to create a separate if condition in here,

129
00:05:36,425 --> 00:05:38,365
which is going to say.

130
00:05:38,360 --> 00:05:43,640
If we should be running away or we should run away.

131
00:05:43,640 --> 00:05:47,800
And where does it end the distance?

132
00:05:47,795 --> 00:05:52,565
Player enemy is less than the runaway range.

133
00:05:52,565 --> 00:05:54,815
So the player is in range,

134
00:05:54,815 --> 00:05:58,525
then we are going to create the direction to move in.

135
00:05:58,520 --> 00:06:01,660
But this time, instead of getting the direction

136
00:06:01,655 --> 00:06:03,385
from the player to chase

137
00:06:03,380 --> 00:06:05,780
position to the transform position,

138
00:06:05,780 --> 00:06:07,670
what we'll do is we'll set

139
00:06:07,670 --> 00:06:12,970
the transform dot position minus the player

140
00:06:12,965 --> 00:06:20,745
to chase dot versus player to chase their hours,

141
00:06:20,745 --> 00:06:25,345
player to chase dot position.

142
00:06:25,344 --> 00:06:27,824
So what this will do is it will

143
00:06:27,820 --> 00:06:30,250
create the same direction to move in,

144
00:06:30,250 --> 00:06:32,080
but in the opposite way.

145
00:06:32,080 --> 00:06:33,600
So this will be negative.

146
00:06:33,595 --> 00:06:36,295
So instead of moving towards the player,

147
00:06:36,295 --> 00:06:39,205
we are going to be moving away from the player.

148
00:06:39,205 --> 00:06:41,005
So we're going to save that.

149
00:06:41,005 --> 00:06:43,195
We are going to go back into our game.

150
00:06:43,195 --> 00:06:45,615
And let's see what we have in here.

151
00:06:45,610 --> 00:06:48,010
So we need to change a couple of things.

152
00:06:48,010 --> 00:06:52,820
So we need to make sure that any day now.

153
00:06:53,160 --> 00:06:57,300
And the new update of unity is very, very annoying.

154
00:06:57,295 --> 00:06:59,205
I've not so many mistakes,

155
00:06:59,200 --> 00:07:01,020
so many glitches in it.

156
00:07:01,015 --> 00:07:02,475
I've had many crashes.

157
00:07:02,470 --> 00:07:05,720
So you can download a better version than the

158
00:07:05,720 --> 00:07:09,620
2020 0.3.15 F2 or whatever it is,

159
00:07:09,620 --> 00:07:10,970
make sure you do that

160
00:07:10,970 --> 00:07:13,100
because I'm not liking this version.

161
00:07:13,100 --> 00:07:16,640
I mean, look how slow it is anyways, any ways.

162
00:07:16,640 --> 00:07:18,670
First of all, is chasing.

163
00:07:18,665 --> 00:07:20,245
We need to make it private

164
00:07:20,240 --> 00:07:23,050
because I don't want to be seeing it all the time.

165
00:07:23,045 --> 00:07:26,975
We don't need to change it private.

166
00:07:26,974 --> 00:07:29,604
And the male, the attacker.

167
00:07:29,600 --> 00:07:31,640
Now what because we won't be implementing

168
00:07:31,640 --> 00:07:34,330
it in this area,

169
00:07:34,325 --> 00:07:36,325
in this part of the course.

170
00:07:36,320 --> 00:07:38,210
Let's just remove it just so we

171
00:07:38,210 --> 00:07:40,360
have a bit more space in here.

172
00:07:40,355 --> 00:07:43,655
So in here we can choose to chase the player

173
00:07:43,655 --> 00:07:48,125
and we need to make sure that we should run away.

174
00:07:48,125 --> 00:07:50,395
And what is the runaway range?

175
00:07:50,390 --> 00:07:53,060
Well, I'm going to issue you a challenge

176
00:07:53,060 --> 00:07:56,050
so that we know what the runaway range is.

177
00:07:56,045 --> 00:07:57,215
And that is to create

178
00:07:57,215 --> 00:08:00,355
a blue circle around the enemy or whatever they want.

179
00:08:00,350 --> 00:08:04,070
So find the onDraw gizmos in it,

180
00:08:04,070 --> 00:08:05,360
create a condition for

181
00:08:05,360 --> 00:08:07,510
the enemy that should be running away.

182
00:08:07,505 --> 00:08:10,645
And choose the blue color or any color that you

183
00:08:10,640 --> 00:08:13,750
want and draw, obviously a sphere.

184
00:08:13,745 --> 00:08:16,255
And as an extra challenge makes sure that we do

185
00:08:16,250 --> 00:08:19,220
not draw any unnecessary circles.

186
00:08:19,220 --> 00:08:23,240
So create also a condition for the chase range,

187
00:08:23,240 --> 00:08:25,310
for example, we don't want to see it if

188
00:08:25,310 --> 00:08:27,700
we are not chasing player.

189
00:08:27,695 --> 00:08:32,525
So that pause the video right now and go to the chat.

190
00:08:32,525 --> 00:08:34,525
Okay, welcome back.

191
00:08:34,520 --> 00:08:39,010
So I'm going to scroll down and he also mainly attacker.

192
00:08:39,005 --> 00:08:41,935
Attacker was actually being used in here.

193
00:08:41,930 --> 00:08:44,330
Okay, no worries about that.

194
00:08:44,330 --> 00:08:47,060
We will remove this.

195
00:08:47,060 --> 00:08:50,900
Okay, so back down here on the,

196
00:08:50,900 --> 00:08:52,220
on drug is most.

197
00:08:52,220 --> 00:08:55,850
So in here we can see that we get the player chase range.

198
00:08:55,850 --> 00:09:00,140
So if we should chase player,

199
00:09:00,140 --> 00:09:02,450
then we are going to,

200
00:09:02,449 --> 00:09:06,859
of course, choose these two and put them

201
00:09:06,860 --> 00:09:11,350
inside the player keep chase.

202
00:09:11,345 --> 00:09:13,945
This is also something that should be inside of

203
00:09:13,940 --> 00:09:17,030
the player chase range.

204
00:09:17,030 --> 00:09:19,850
Or I mean in the should chase player.

205
00:09:19,850 --> 00:09:23,630
There we go. If the shooting range okay,

206
00:09:23,630 --> 00:09:25,390
for that, Let's keep it as it is.

207
00:09:25,385 --> 00:09:26,605
And finally, we're going to

208
00:09:26,600 --> 00:09:28,130
create an if statement in here,

209
00:09:28,130 --> 00:09:32,050
which we'll say if we should runaway,

210
00:09:32,045 --> 00:09:33,985
then we are going to get

211
00:09:33,980 --> 00:09:37,410
the gizmos dot color

212
00:09:37,414 --> 00:09:40,324
and it's going to be equal to color also.

213
00:09:40,325 --> 00:09:42,085
We are already using blue,

214
00:09:42,080 --> 00:09:46,550
so let's use yellow, green, green.

215
00:09:46,550 --> 00:09:48,440
So there we go, green.

216
00:09:48,440 --> 00:09:51,620
And we're going to copy this line in

217
00:09:51,620 --> 00:09:54,880
here because it's almost the same except for the,

218
00:09:54,875 --> 00:09:58,885
of the shooting range, the runaway range.

219
00:09:58,880 --> 00:10:00,070
Save that.

220
00:10:00,065 --> 00:10:01,955
Remove the extra spaces in here.

221
00:10:01,955 --> 00:10:03,475
And now we have a way to

222
00:10:03,470 --> 00:10:05,810
measure the distance that we are going to be

223
00:10:05,810 --> 00:10:09,980
running away with k. So there we go.

224
00:10:09,980 --> 00:10:11,390
We have the blue range,

225
00:10:11,390 --> 00:10:14,420
which is the one for the shooting.

226
00:10:14,420 --> 00:10:17,470
Okay, great. And then we have the runaway range.

227
00:10:17,465 --> 00:10:21,035
So okay, so when the player gets in this range,

228
00:10:21,035 --> 00:10:23,455
the enemy should start running away.

229
00:10:23,450 --> 00:10:24,970
So that's run the game.

230
00:10:24,965 --> 00:10:26,825
And let's see how that works.

231
00:10:26,825 --> 00:10:28,535
So now we are in the game.

232
00:10:28,535 --> 00:10:30,245
We come close to the enemy.

233
00:10:30,245 --> 00:10:33,535
There we go, you can see that he is running away from us.

234
00:10:33,530 --> 00:10:36,410
If I tried to move faster, he starts moving.

235
00:10:36,410 --> 00:10:37,730
Well, that's because he is slow.

236
00:10:37,730 --> 00:10:39,830
Obviously we are going to make him a

237
00:10:39,830 --> 00:10:43,010
bit maybe faster because he's a flying enemy.

238
00:10:43,010 --> 00:10:44,990
So now when I tried to come close,

239
00:10:44,990 --> 00:10:46,670
he keeps getting away.

240
00:10:46,670 --> 00:10:48,740
So hey, well, and he even

241
00:10:48,740 --> 00:10:50,900
called us because as we are chasing him,

242
00:10:50,900 --> 00:10:52,640
he is throwing projectiles.

243
00:10:52,640 --> 00:10:53,230
Honest.

244
00:10:53,225 --> 00:10:55,465
And also one thing I forgot to mention,

245
00:10:55,460 --> 00:10:58,220
I changed the five position.

246
00:10:58,220 --> 00:10:59,900
Nope, it's the same place.

247
00:10:59,900 --> 00:11:02,720
I'm going to make it on top of his head or maybe,

248
00:11:02,720 --> 00:11:05,540
you know what, let's just keep it where it was.

249
00:11:05,540 --> 00:11:08,560
I think that was good. Anyways, I hope you enjoy it.

250
00:11:08,555 --> 00:11:10,795
I hope you understood what is happening in

251
00:11:10,790 --> 00:11:13,460
here because where is it?

252
00:11:13,460 --> 00:11:14,240
Okay?

253
00:11:14,240 --> 00:11:16,850
So if we should run away, instead of,

254
00:11:16,850 --> 00:11:18,950
we have the player position and

255
00:11:18,950 --> 00:11:21,190
bigger than the transformed position.

256
00:11:21,185 --> 00:11:22,705
Or at least not, not just

257
00:11:22,700 --> 00:11:25,000
bigger it on the other direction.

258
00:11:24,995 --> 00:11:27,625
If we choose to remove

259
00:11:27,620 --> 00:11:32,990
the transform position from the player to chase position,

260
00:11:32,990 --> 00:11:34,610
we get a positive,

261
00:11:34,610 --> 00:11:37,250
so we are moving towards the player.

262
00:11:37,250 --> 00:11:40,790
If we remove our position from the player's position,

263
00:11:40,790 --> 00:11:43,300
then we are moving away from the player.

264
00:11:43,295 --> 00:11:45,515
So with that done, I hope you enjoy it.

265
00:11:45,515 --> 00:11:49,225
And the next video we will be creating the wanderer.

266
00:11:49,220 --> 00:11:50,800
So I'll see you then.

267
00:11:50,795 --> 00:11:52,465
And don't forget, of course,

268
00:11:52,460 --> 00:11:55,710
to commit your changes every single time.

