1
00:00:00,000 --> 00:00:01,000
Hello, guys.

2
00:00:01,000 --> 00:00:03,000
In this video, I want to show you how to make an enemy.

3
00:00:03,000 --> 00:00:10,000
I actually one of the students pointed out that we have this enemy eye in the promo video, but there

4
00:00:10,000 --> 00:00:12,000
is no such thing in the course.

5
00:00:12,000 --> 00:00:18,000
And that was indeed true because when I created course for the first time, I kind of felt like, well,

6
00:00:18,000 --> 00:00:20,000
why not to add a bonus content?

7
00:00:20,000 --> 00:00:26,000
And then when I did recreation of this, you know, reworking the course, I thought, well, I don't

8
00:00:26,000 --> 00:00:30,000
know if people actually need it, but apparently people need this, so I'm going to make it.

9
00:00:30,000 --> 00:00:33,000
And there are two options for doing this.

10
00:00:33,000 --> 00:00:39,000
First of all, we could use the player script and all of this information to make an enemy.

11
00:00:39,000 --> 00:00:43,000
We could use inheritance, we could override functions, we could use same values to not make a new

12
00:00:43,000 --> 00:00:45,000
one with the same name.

13
00:00:45,000 --> 00:00:50,000
So this would save us some time, but I'm afraid it might bring some confusion in the way of making

14
00:00:50,000 --> 00:00:54,000
it, because we did not plan to do it at the beginning.

15
00:00:54,000 --> 00:01:00,000
So now I would have to override some functions, some values I would have to inherit somebody.

16
00:01:00,000 --> 00:01:03,000
It's not and I don't want to confuse anyone with this process.

17
00:01:03,000 --> 00:01:04,000
So better.

18
00:01:04,000 --> 00:01:08,000
Let's make it from zero like it's a completely new object.

19
00:01:08,000 --> 00:01:12,000
Besides, maybe you want to do this for some other project in which you don't have entire player script

20
00:01:12,000 --> 00:01:13,000
created.

21
00:01:13,000 --> 00:01:16,000
So we're going to do it from start from zero.

22
00:01:16,000 --> 00:01:18,000
Although I want to save me some time.

23
00:01:18,000 --> 00:01:21,000
I don't want to make an entire everything from the beginning.

24
00:01:21,000 --> 00:01:26,000
So I'm going to take a player, duplicate this and give it name of the enemy.

25
00:01:27,000 --> 00:01:29,000
Can I delete the script?

26
00:01:29,000 --> 00:01:30,000
All right.

27
00:01:30,000 --> 00:01:35,000
But still, we have the rigid body and a capsule collider on this, and we have a legit check that we're

28
00:01:35,000 --> 00:01:36,000
going to use later.

29
00:01:36,000 --> 00:01:40,000
For now, I'm going to just switch it off as well as the dust and these two.

30
00:01:40,000 --> 00:01:41,000
I don't need it now.

31
00:01:41,000 --> 00:01:43,000
I need only well, check.

32
00:01:43,000 --> 00:01:44,000
So we have the enemy.

33
00:01:44,000 --> 00:01:47,000
I'm going to make it red so it is more noticeable.

34
00:01:48,000 --> 00:01:52,000
Like we know this is the enemy and I'm going to switch off player so it gets out of my way.

35
00:01:54,000 --> 00:01:54,000
Very nice.

36
00:01:54,000 --> 00:01:57,000
We also need animator controller for this guy.

37
00:01:57,000 --> 00:02:03,000
So let's go to assets animation and I can see we don't really have a folders for everything, so we

38
00:02:03,000 --> 00:02:04,000
can just.

39
00:02:05,000 --> 00:02:08,000
Create a folder enemy.

40
00:02:08,000 --> 00:02:15,000
Let's go inside and make animator controller enemy, AC.

41
00:02:16,000 --> 00:02:18,000
I'm going to drag this on the enemy here.

42
00:02:19,000 --> 00:02:20,000
Go to animator.

43
00:02:20,000 --> 00:02:25,000
And we actually could use a couple of animations from the player like idle and walk.

44
00:02:25,000 --> 00:02:26,000
Right?

45
00:02:26,000 --> 00:02:27,000
We could do this.

46
00:02:27,000 --> 00:02:30,000
So let's go to player and copy this idle move.

47
00:02:32,000 --> 00:02:34,000
This is basically you know what it is, right?

48
00:02:34,000 --> 00:02:37,000
Just idle and move animation in a bland tree.

49
00:02:37,000 --> 00:02:39,000
Nothing the big about it.

50
00:02:39,000 --> 00:02:41,000
We did it in the very beginning of the course.

51
00:02:41,000 --> 00:02:43,000
So I'm going to just take it.

52
00:02:43,000 --> 00:02:47,000
Press control C go to the enemy's animator and paste it here.

53
00:02:47,000 --> 00:02:50,000
So now we have idle move animations for the enemy.

54
00:02:50,000 --> 00:02:53,000
Now let's make a script and do a bit of a set up.

55
00:02:53,000 --> 00:02:56,000
I'm going to make I'm going to make it in the scripts folder.

56
00:02:59,000 --> 00:03:00,000
Enemy.

57
00:03:07,000 --> 00:03:10,000
Can I drag it on the enemy and let's go inside of a script.

58
00:03:11,000 --> 00:03:13,000
We need a lot of things here.

59
00:03:13,000 --> 00:03:14,000
We need.

60
00:03:15,000 --> 00:03:17,000
And rigid body to the army.

61
00:03:17,000 --> 00:03:22,000
We need the animator so private animator anim and also we don't need these two for now.

62
00:03:22,000 --> 00:03:23,000
So I'm going to delete them.

63
00:03:24,000 --> 00:03:25,000
All right.

64
00:03:25,000 --> 00:03:26,000
We need animator.

65
00:03:26,000 --> 00:03:27,000
Collider.

66
00:03:27,000 --> 00:03:29,000
I'm not sure we need the collider now, so I'm not going to make it.

67
00:03:31,000 --> 00:03:33,000
Let's go to start and get component of those.

68
00:03:33,000 --> 00:03:39,000
So our B equals to get component of rigid body and equals to get component of animator.

69
00:03:39,000 --> 00:03:45,000
We want to have update in which we're going to have an animator controllers function so animate our

70
00:03:45,000 --> 00:03:52,000
controllers and I'm going to click alt enter to generate method in which I'm going to set up float of

71
00:03:52,000 --> 00:03:52,000
the x.

72
00:03:52,000 --> 00:04:02,000
So any set float of the x velocity to RB velocity dot x, very good.

73
00:04:02,000 --> 00:04:06,000
Now let's actually move there B so we're going to make a header.

74
00:04:07,000 --> 00:04:09,000
Movement details.

75
00:04:09,000 --> 00:04:11,000
And here we're going to have sterilized field.

76
00:04:14,000 --> 00:04:17,000
Private float more speed and we need the jump first.

77
00:04:17,000 --> 00:04:22,000
So I serialize field private float jump force which we're going to use later to make a jump.

78
00:04:22,000 --> 00:04:26,000
As of now, I guess this is enough.

79
00:04:26,000 --> 00:04:29,000
Let's add a bit of functionality to make him move.

80
00:04:29,000 --> 00:04:35,000
So it's going to be RB velocity equals new vector to move speed and for the y RB velocity dot y.

81
00:04:35,000 --> 00:04:38,000
So this supposed to just make him move, right?

82
00:04:38,000 --> 00:04:43,000
I'm going to make a boolean so I can control his movement, public ball can move.

83
00:04:43,000 --> 00:04:48,000
And in the update I'm going to say if can move, then move.

84
00:04:50,000 --> 00:04:51,000
All right, Let's go and see this.

85
00:04:59,000 --> 00:05:02,000
Going to set move speed to five.

86
00:05:02,000 --> 00:05:03,000
Jump first to 15.

87
00:05:03,000 --> 00:05:05,000
Go to play mode.

88
00:05:06,000 --> 00:05:08,000
He's just standing there can move.

89
00:05:08,000 --> 00:05:11,000
He goes and he never stops.

90
00:05:11,000 --> 00:05:12,000
But it is okay.

91
00:05:12,000 --> 00:05:13,000
Very nice.

92
00:05:13,000 --> 00:05:13,000
I like it a lot.

93
00:05:13,000 --> 00:05:16,000
Now, let's make him stop if we want to.

94
00:05:16,000 --> 00:05:17,000
Just in case.

95
00:05:17,000 --> 00:05:19,000
So I'm going to wrap this up in the method.

96
00:05:19,000 --> 00:05:21,000
I'll tender extract method.

97
00:05:23,000 --> 00:05:30,000
Movement else it's going to be just RB velocity equals to new vector to zero and RB velocity on the

98
00:05:30,000 --> 00:05:30,000
Y.

99
00:05:30,000 --> 00:05:32,000
So if he cannot move, he's not going to move.

100
00:05:32,000 --> 00:05:33,000
Very good.

101
00:05:33,000 --> 00:05:37,000
And then we can use this boolean maybe later in case we need it.

102
00:05:37,000 --> 00:05:42,000
Now what I want to do, you see, just now he ran off the platform, not what I want.

103
00:05:42,000 --> 00:05:46,000
I want him to jump when there is no ground in front of us.

104
00:05:46,000 --> 00:05:48,000
And we need to make a collision check for this.

105
00:05:49,000 --> 00:05:53,000
Going to be a lot of work to do, but I'm planning to make a cheap trick.

106
00:05:53,000 --> 00:05:57,000
I'm going to copy code from the player here.

107
00:05:58,000 --> 00:05:58,000
Yeah.

108
00:05:58,000 --> 00:06:03,000
This one I was talking about when I told you that we could just override some functions from the player,

109
00:06:03,000 --> 00:06:04,000
but we're not going to do it.

110
00:06:05,000 --> 00:06:06,000
Let's just copy this.

111
00:06:07,000 --> 00:06:16,000
Because this would have less confusion, even though actually inheriting functions is more correct to

112
00:06:16,000 --> 00:06:16,000
do.

113
00:06:16,000 --> 00:06:22,000
Yeah, but if you want to learn more about inheritance, maybe check out my course about RPG game,

114
00:06:22,000 --> 00:06:26,000
the one you can see it on my instructor page or on my YouTube channel.

115
00:06:26,000 --> 00:06:28,000
Going to be a lot of stuff with inheritance.

116
00:06:28,000 --> 00:06:30,000
A lot of things like skills.

117
00:06:30,000 --> 00:06:37,000
You know, it's an RPG game with items, experience, statistic stats, so many things and we're going

118
00:06:37,000 --> 00:06:39,000
to use their inheritance a lot.

119
00:06:39,000 --> 00:06:41,000
So maybe check that out if you want.

120
00:06:42,000 --> 00:06:44,000
Now I'm going to paste all of that.

121
00:06:44,000 --> 00:06:45,000
What I just copied.

122
00:06:45,000 --> 00:06:47,000
I'm going to see what I need from this later.

123
00:06:47,000 --> 00:06:48,000
As of now, I'm going to keep it like this.

124
00:06:48,000 --> 00:06:52,000
I only want to make another transform serialize field.

125
00:06:55,000 --> 00:06:57,000
Private transform ground.

126
00:06:57,000 --> 00:06:59,000
Check all of this you've seen before.

127
00:06:59,000 --> 00:07:01,000
I believe in the beginning of the course.

128
00:07:01,000 --> 00:07:03,000
These things are pretty simple.

129
00:07:06,000 --> 00:07:08,000
Can I make another boolean?

130
00:07:08,000 --> 00:07:09,000
Private bool.

131
00:07:11,000 --> 00:07:13,000
And ground forward.

132
00:07:14,000 --> 00:07:15,000
All right.

133
00:07:15,000 --> 00:07:16,000
And.

134
00:07:19,000 --> 00:07:20,000
I want to have transform for this as well.

135
00:07:20,000 --> 00:07:25,000
So serialize field private transform ground forward check.

136
00:07:26,000 --> 00:07:27,000
Very nice.

137
00:07:27,000 --> 00:07:28,000
I like it.

138
00:07:29,000 --> 00:07:31,000
Now we need collision functions.

139
00:07:31,000 --> 00:07:36,000
And also I'm going to be a cheater and I'm going to go below the player and copy them.

140
00:07:43,000 --> 00:07:47,000
And as I was saying, it would be better to use inheritance for this.

141
00:07:47,000 --> 00:07:52,000
But as I was saying after that, I want to show you this creation of the enemy in a vacuum.

142
00:07:52,000 --> 00:07:55,000
Like there is no other script, like you have an empty project.

143
00:07:55,000 --> 00:07:57,000
So we're going to copy and paste code.

144
00:07:57,000 --> 00:07:58,000
Yeah.

145
00:07:58,000 --> 00:08:02,000
So check collision, we have this done.

146
00:08:02,000 --> 00:08:04,000
And I want to add another thing here.

147
00:08:04,000 --> 00:08:07,000
First of all, I want to change this transform position of the ground.

148
00:08:07,000 --> 00:08:10,000
Check to ground check that we created.

149
00:08:12,000 --> 00:08:13,000
Here as well.

150
00:08:15,000 --> 00:08:16,000
Ground check.

151
00:08:17,000 --> 00:08:18,000
Ground check.

152
00:08:18,000 --> 00:08:21,000
And I want to make one more check here.

153
00:08:22,000 --> 00:08:28,000
And ground forward equals to physics, to the cost.

154
00:08:29,000 --> 00:08:31,000
Ground forward position.

155
00:08:37,000 --> 00:08:37,000
Wait a second.

156
00:08:37,000 --> 00:08:39,000
Ground forward.

157
00:08:39,000 --> 00:08:41,000
Check that position.

158
00:08:41,000 --> 00:08:43,000
Vector two down.

159
00:08:43,000 --> 00:08:46,000
We can use ground check distance for this.

160
00:08:46,000 --> 00:08:48,000
And what is ground?

161
00:08:48,000 --> 00:08:50,000
And we need to draw this line on the gizmos.

162
00:08:50,000 --> 00:08:51,000
So I'm going to do it.

163
00:08:51,000 --> 00:08:54,000
I'm going to just duplicate this line of code and change ground.

164
00:08:54,000 --> 00:08:55,000
Check to ground forward.

165
00:08:55,000 --> 00:08:56,000
Check.

166
00:08:56,000 --> 00:08:58,000
Let me copy this.

167
00:09:00,000 --> 00:09:01,000
Paste this in.

168
00:09:02,000 --> 00:09:03,000
Paste this in.

169
00:09:04,000 --> 00:09:07,000
And paste this in.

170
00:09:08,000 --> 00:09:09,000
All right.

171
00:09:09,000 --> 00:09:11,000
So we have gizmos and we have check collision.

172
00:09:11,000 --> 00:09:13,000
We need to add this function to update.

173
00:09:13,000 --> 00:09:15,000
Otherwise, it won't work.

174
00:09:16,000 --> 00:09:17,000
Check collision.

175
00:09:19,000 --> 00:09:22,000
Yeah, I like it.

176
00:09:22,000 --> 00:09:25,000
Now let's go to update and make simple if statement.

177
00:09:25,000 --> 00:09:31,000
If is grounded and no ground forward, then we're going to jump.

178
00:09:32,000 --> 00:09:39,000
RB Velocity equals to new vector to RB velocity dot x and for the Y it's going to be jump force.

179
00:09:42,000 --> 00:09:43,000
Simple, right?

180
00:09:43,000 --> 00:09:44,000
Pretty simple.

181
00:09:45,000 --> 00:09:46,000
Let's go back to Unity.

182
00:09:51,000 --> 00:09:57,000
I'm going to add create empty forward ground check.

183
00:09:57,000 --> 00:09:59,000
I'm going to place it here.

184
00:09:59,000 --> 00:10:00,000
Maybe here.

185
00:10:00,000 --> 00:10:03,000
I like it like it here more.

186
00:10:03,000 --> 00:10:04,000
Now, ground check.

187
00:10:04,000 --> 00:10:09,000
Let's assign it Ground for check and we'll check.

188
00:10:10,000 --> 00:10:12,000
Or it has different name ground forward check.

189
00:10:14,000 --> 00:10:17,000
Giving a second round forward.

190
00:10:18,000 --> 00:10:21,000
Now let's give them a distance and so on.

191
00:10:21,000 --> 00:10:23,000
So ground check distance, just like so.

192
00:10:23,000 --> 00:10:30,000
Going to place ground, check at the feet of the character and go and check forward the feet and to

193
00:10:30,000 --> 00:10:35,000
the right like So maybe we can decrease distance by a bit.

194
00:10:37,000 --> 00:10:38,000
Something like this.

195
00:10:38,000 --> 00:10:40,000
So point seven will do.

196
00:10:40,000 --> 00:10:42,000
Now, what is ground?

197
00:10:42,000 --> 00:10:42,000
Ground?

198
00:10:43,000 --> 00:10:45,000
We're not going to use ceiling checked for now.

199
00:10:45,000 --> 00:10:47,000
And this supposed to work?

200
00:10:47,000 --> 00:10:51,000
I'm going to place him here, hit the play and see this can move.

201
00:10:52,000 --> 00:10:53,000
Run and jump.

202
00:10:54,000 --> 00:10:55,000
Nice.

203
00:10:55,000 --> 00:10:56,000
I like it.

204
00:10:56,000 --> 00:10:58,000
Now, let's set up animator.

205
00:10:58,000 --> 00:11:01,000
Let's add that jump full animation.

206
00:11:01,000 --> 00:11:02,000
Right.

207
00:11:02,000 --> 00:11:04,000
We have this on the player, I believe.

208
00:11:04,000 --> 00:11:07,000
I just don't want to create animations again.

209
00:11:07,000 --> 00:11:09,000
We have this jump fall.

210
00:11:09,000 --> 00:11:10,000
I'm going to copy it.

211
00:11:12,000 --> 00:11:14,000
Going to enemy base this in.

212
00:11:17,000 --> 00:11:19,000
We need to set up velocity.

213
00:11:19,000 --> 00:11:22,000
Don't forget about this and let's make a boolean.

214
00:11:22,000 --> 00:11:25,000
Bull is grounded.

215
00:11:27,000 --> 00:11:30,000
And if I'm not wrong from any state, we make transition to jump fall.

216
00:11:31,000 --> 00:11:35,000
If not is grounded is grounded false.

217
00:11:35,000 --> 00:11:36,000
We go there.

218
00:11:37,000 --> 00:11:46,000
Duration zero can transit to self and check and then back to idle move if is grounded so is grounded

219
00:11:46,000 --> 00:11:46,000
true.

220
00:11:48,000 --> 00:11:50,000
Has extra time and check duration zero.

221
00:11:53,000 --> 00:11:54,000
Can I make it pretty?

222
00:11:55,000 --> 00:11:57,000
And then let's set up this in the cold as well.

223
00:11:57,000 --> 00:12:05,000
Let's go back to code and then emitter controllers, we're going to set up Y and set float y velocity

224
00:12:05,000 --> 00:12:09,000
to RB, velocity dot y and as well.

225
00:12:09,000 --> 00:12:12,000
And set bool.

226
00:12:13,000 --> 00:12:15,000
Is grounded.

227
00:12:15,000 --> 00:12:17,000
Too is grounded.

228
00:12:19,000 --> 00:12:19,000
Nice.

229
00:12:19,000 --> 00:12:21,000
Let me double check.

230
00:12:21,000 --> 00:12:23,000
Want to be sure it's working and.

231
00:12:26,000 --> 00:12:26,000
Go.

232
00:12:29,000 --> 00:12:30,000
Yes.

233
00:12:30,000 --> 00:12:31,000
Perfect.

234
00:12:31,000 --> 00:12:39,000
Now, the funny part, I'm not even sure we need this, but I want to make it.

235
00:12:40,000 --> 00:12:42,000
Let's check for the enemy.

236
00:12:43,000 --> 00:12:47,000
Luckily we have a bunch of functionality here and.

237
00:12:49,000 --> 00:12:59,000
This one needs a player because we change in player Sledge detected boolean on this script so we would

238
00:12:59,000 --> 00:13:01,000
have to change this by a bit, I guess.

239
00:13:03,000 --> 00:13:05,000
How could we change this?

240
00:13:06,000 --> 00:13:11,000
We could use player to read boolean from this object, but that is working nice.

241
00:13:11,000 --> 00:13:13,000
So I don't want to break it.

242
00:13:13,000 --> 00:13:14,000
I'm just going to do here.

243
00:13:14,000 --> 00:13:19,000
If player not equals to null and can detect.

244
00:13:19,000 --> 00:13:25,000
So this one will work only if there is a component of a player write assigned.

245
00:13:25,000 --> 00:13:27,000
That's why that's how it's going to work.

246
00:13:27,000 --> 00:13:30,000
And then we're going to add another component here.

247
00:13:30,000 --> 00:13:33,000
Serialize field private enemy enemy.

248
00:13:34,000 --> 00:13:36,000
And just add here.

249
00:13:36,000 --> 00:13:43,000
If enemy not equals to null and can detect, then we're going to duplicate this and instead of player

250
00:13:43,000 --> 00:13:45,000
we're going to type here enemy.

251
00:13:46,000 --> 00:13:47,000
All right, so.

252
00:13:48,000 --> 00:13:48,000
Yeah.

253
00:13:48,000 --> 00:13:49,000
Kind of work around.

254
00:13:49,000 --> 00:13:50,000
But I think this.

255
00:13:50,000 --> 00:13:51,000
This is okay.

256
00:13:51,000 --> 00:13:52,000
Looks good.

257
00:13:52,000 --> 00:13:55,000
Let's close this and let's go all the way above.

258
00:13:55,000 --> 00:14:00,000
Find this ledge detected boolean and I'm going to make it just public without hiding.

259
00:14:00,000 --> 00:14:02,000
Inspect so I can see if Ledge was detected or not.

260
00:14:02,000 --> 00:14:04,000
Let's go and check this out.

261
00:14:04,000 --> 00:14:06,000
Just going to click the lock it so it is logged in.

262
00:14:06,000 --> 00:14:09,000
I can see it always and going to go to play mode.

263
00:14:11,000 --> 00:14:14,000
Find some platform and place in front of him.

264
00:14:16,000 --> 00:14:16,000
Yeah.

265
00:14:16,000 --> 00:14:18,000
Platform selected.

266
00:14:19,000 --> 00:14:22,000
We can see ledge detected here.

267
00:14:22,000 --> 00:14:23,000
So.

268
00:14:25,000 --> 00:14:26,000
True False.

269
00:14:26,000 --> 00:14:27,000
True False.

270
00:14:27,000 --> 00:14:28,000
True, false.

271
00:14:29,000 --> 00:14:29,000
Great.

272
00:14:29,000 --> 00:14:32,000
Now let's make a functionality for kitchen this ledge.

273
00:14:33,000 --> 00:14:37,000
This would take some work because I don't remember how I did it.

274
00:14:38,000 --> 00:14:38,000
Let me see.

275
00:14:44,000 --> 00:14:45,000
Let's climb region.

276
00:14:46,000 --> 00:14:46,000
Wow.

277
00:14:46,000 --> 00:14:47,000
I'm so smart.

278
00:14:47,000 --> 00:14:48,000
The region.

279
00:14:48,000 --> 00:14:49,000
Entire region.

280
00:14:49,000 --> 00:14:50,000
So I can see it.

281
00:14:51,000 --> 00:14:52,000
Good.

282
00:14:52,000 --> 00:14:54,000
Let's just copy this region then.

283
00:14:54,000 --> 00:14:57,000
Control C, go to the enemy.

284
00:14:58,000 --> 00:15:00,000
Paste this in.

285
00:15:05,000 --> 00:15:08,000
We need to acknowledge in the update.

286
00:15:11,000 --> 00:15:12,000
Check foliage.

287
00:15:14,000 --> 00:15:15,000
And we need to set up animation.

288
00:15:15,000 --> 00:15:19,000
If I'm not wrong, let's go back in the animator.

289
00:15:19,000 --> 00:15:21,000
We're going to select player.

290
00:15:21,000 --> 00:15:23,000
Find this ledge climb.

291
00:15:23,000 --> 00:15:25,000
Check how it works and click this.

292
00:15:25,000 --> 00:15:25,000
Lock it.

293
00:15:25,000 --> 00:15:29,000
So we have a transition from any state if can climb through.

294
00:15:29,000 --> 00:15:36,000
And we also need to make sure it can climb false when we do in fall and jump and then go back with the

295
00:15:36,000 --> 00:15:38,000
exit time of one know condition.

296
00:15:40,000 --> 00:15:40,000
Good.

297
00:15:40,000 --> 00:15:43,000
So I'm going to just copy this player.

298
00:15:43,000 --> 00:15:44,000
Let's climb.

299
00:15:45,000 --> 00:15:50,000
With a transition copy, go to enemy paste.

300
00:15:50,000 --> 00:15:51,000
Paste.

301
00:15:51,000 --> 00:15:52,000
Here we have it.

302
00:15:54,000 --> 00:15:56,000
Come fall, any state ledge climb.

303
00:15:58,000 --> 00:15:58,000
Give me a second.

304
00:15:58,000 --> 00:15:59,000
I'll make it pretty.

305
00:16:02,000 --> 00:16:05,000
So we need a boolean can climb if I'm not wrong.

306
00:16:07,000 --> 00:16:08,000
Can climb.

307
00:16:08,000 --> 00:16:12,000
Honestly, I did it so long ago, I don't really remember.

308
00:16:13,000 --> 00:16:14,000
Can claim true.

309
00:16:16,000 --> 00:16:17,000
All right.

310
00:16:17,000 --> 00:16:21,000
So going to climb true make transition to Idol.

311
00:16:21,000 --> 00:16:29,000
With the exit time of one transition duration zero, we need to make sure can transit a self unchecked

312
00:16:29,000 --> 00:16:34,000
and from any state to jump fall we need to make sure can climb is.

313
00:16:35,000 --> 00:16:37,000
False here.

314
00:16:38,000 --> 00:16:40,000
Okay, Now it shows me some error.

315
00:16:40,000 --> 00:16:41,000
Let me see.

316
00:16:42,000 --> 00:16:44,000
Which does not exist in the controller.

317
00:16:45,000 --> 00:16:45,000
What do you mean?

318
00:16:45,000 --> 00:16:46,000
It does exist.

319
00:16:46,000 --> 00:16:46,000
Here it is.

320
00:16:46,000 --> 00:16:47,000
Can climb.

321
00:16:48,000 --> 00:16:48,000
Okay,

322
00:16:51,000 --> 00:16:55,000
Now we need to go to the enemy animation.

323
00:16:55,000 --> 00:16:57,000
Find ledge climb.

324
00:16:57,000 --> 00:17:00,000
Make sure there is an event and there is ledge.

325
00:17:00,000 --> 00:17:01,000
Climb over.

326
00:17:01,000 --> 00:17:02,000
Very good.

327
00:17:02,000 --> 00:17:03,000
Very, very good.

328
00:17:03,000 --> 00:17:05,000
Now we need to ascend.

329
00:17:05,000 --> 00:17:09,000
Boolean of can climb because otherwise it won't work in the animator controller.

330
00:17:09,000 --> 00:17:15,000
We can just do any set bull can climb to can climb.

331
00:17:15,000 --> 00:17:20,000
And also I want to make enemy jump when he sees the wall so it's easier to test And also.

332
00:17:20,000 --> 00:17:22,000
Well it works as it's supposed to be.

333
00:17:22,000 --> 00:17:29,000
Let's go to update and in the place we call in for jump we can do or we'll detect it, then you're going

334
00:17:29,000 --> 00:17:29,000
to jump.

335
00:17:29,000 --> 00:17:32,000
Now we need to set up offset in the unity.

336
00:17:32,000 --> 00:17:36,000
So here in the unity, we need to select enemy and do a couple of things.

337
00:17:36,000 --> 00:17:39,000
First of all, I would like to decrease ground check just by a bit.

338
00:17:39,000 --> 00:17:44,000
So maybe point five is okay because we don't really need it so long and the longer it is, the more

339
00:17:44,000 --> 00:17:47,000
he would have chance to jump off the air.

340
00:17:47,000 --> 00:17:53,000
So better keep it lower and we'll check size should be there as well because now it is zero.

341
00:17:53,000 --> 00:17:57,000
So maybe point five and for the Y, I don't know, 1.5 is okay.

342
00:17:58,000 --> 00:18:04,000
Now we need the offset of the ledge and I'm going to copy values from the player.

343
00:18:04,000 --> 00:18:10,000
If you don't know how large check works, you better go and check the video about that in the middle

344
00:18:10,000 --> 00:18:17,000
of the course where we describe in details, in DB details, how do we make let's check in general entire

345
00:18:17,000 --> 00:18:17,000
video.

346
00:18:17,000 --> 00:18:23,000
This video is so quick and paste because all of these things, all of the aspects we did before, during

347
00:18:23,000 --> 00:18:27,000
the course and this all is just summary of the code we used before.

348
00:18:27,000 --> 00:18:28,000
It's supposed to be very easy.

349
00:18:28,000 --> 00:18:33,000
So that's why I'm doing everything so quick without really stepping on details.

350
00:18:33,000 --> 00:18:34,000
Right.

351
00:18:34,000 --> 00:18:36,000
And let's set up offset.

352
00:18:36,000 --> 00:18:38,000
I know it because I've said it on the player.

353
00:18:38,000 --> 00:18:42,000
So it is this one and -132.

354
00:18:42,000 --> 00:18:43,000
Can I go back to enemy?

355
00:18:45,000 --> 00:18:46,000
-132.

356
00:18:48,000 --> 00:18:55,000
Or the second offset 57 133 so point 57 133.

357
00:18:56,000 --> 00:18:56,000
All right.

358
00:18:57,000 --> 00:19:03,000
Now, let me take a prefab of some level part and place it in front of him somewhere here.

359
00:19:05,000 --> 00:19:06,000
Okay, let's go.

360
00:19:06,000 --> 00:19:07,000
Come on, boy.

361
00:19:07,000 --> 00:19:08,000
You can do it.

362
00:19:10,000 --> 00:19:11,000
And.

363
00:19:11,000 --> 00:19:12,000
Yeah.

364
00:19:13,000 --> 00:19:14,000
Nice.

365
00:19:14,000 --> 00:19:15,000
Look at this guy.

366
00:19:15,000 --> 00:19:16,000
Look at him.

367
00:19:16,000 --> 00:19:17,000
Go.

368
00:19:17,000 --> 00:19:20,000
Yeah, It looks a bit clunky, but we're going to improve it.

369
00:19:21,000 --> 00:19:22,000
I like it.

370
00:19:22,000 --> 00:19:23,000
I really like it.

371
00:19:26,000 --> 00:19:29,000
Well, let's make him to take the coins before I forgot.

372
00:19:29,000 --> 00:19:30,000
All right.

373
00:19:30,000 --> 00:19:32,000
We're going to go to Coin prefab.

374
00:19:33,000 --> 00:19:33,000
Where is it?

375
00:19:34,000 --> 00:19:34,000
Coin.

376
00:19:36,000 --> 00:19:37,000
Here we pick an icon.

377
00:19:37,000 --> 00:19:41,000
If it is a player, what they want to do is to make another check.

378
00:19:41,000 --> 00:19:44,000
If collision get component of enemy.

379
00:19:45,000 --> 00:19:51,000
Not because to know, then we're just going to destroy, object, destroy game object.

380
00:19:51,000 --> 00:19:54,000
So player won't get any coins if he did not pick up at first.

381
00:19:56,000 --> 00:19:57,000
Going to save this.

382
00:19:57,000 --> 00:20:00,000
Now you're going to collect the coins and.

383
00:20:01,000 --> 00:20:02,000
Yeah.

384
00:20:02,000 --> 00:20:06,000
Let me double check the animator, because I think it looks not as pretty as I would like it to see.

385
00:20:07,000 --> 00:20:08,000
Animator of the enemy.

386
00:20:08,000 --> 00:20:11,000
We have a ledge climb, jump, fall.

387
00:20:12,000 --> 00:20:14,000
And it stayed good enough.

388
00:20:14,000 --> 00:20:15,000
What do you think?

389
00:20:16,000 --> 00:20:17,000
I think, yes.

390
00:20:18,000 --> 00:20:22,000
Now let's adjust his behavior a bit so he moves more smoothly.

391
00:20:22,000 --> 00:20:24,000
Not like now.

392
00:20:24,000 --> 00:20:25,000
Like a clunky and funny.

393
00:20:26,000 --> 00:20:28,000
First of all, we want him to be faster.

394
00:20:28,000 --> 00:20:35,000
And the speed, the speed of the character should be should be adjusted to the speed of the player.

395
00:20:35,000 --> 00:20:35,000
Right.

396
00:20:36,000 --> 00:20:38,000
So I'm going to take my level generator.

397
00:20:40,000 --> 00:20:44,000
And place only one platform that is just a straight platform.

398
00:20:45,000 --> 00:20:47,000
Or is it little generator?

399
00:20:47,000 --> 00:20:49,000
Place level Part six.

400
00:20:51,000 --> 00:20:52,000
Can I delete this?

401
00:20:54,000 --> 00:20:56,000
Go to play mode to see him run.

402
00:20:59,000 --> 00:21:01,000
He's going to run forward.

403
00:21:07,000 --> 00:21:11,000
All right, now let's open the enemy and make a speed controller function.

404
00:21:12,000 --> 00:21:13,000
Going to be a bit different.

405
00:21:13,000 --> 00:21:16,000
Private void, speed controller.

406
00:21:16,000 --> 00:21:19,000
And we need reference to the player this time.

407
00:21:19,000 --> 00:21:23,000
So I'm going to make a component of a player, private player, player.

408
00:21:24,000 --> 00:21:31,000
We're going to go to start and say player equals to game manager, instance player.

409
00:21:32,000 --> 00:21:32,000
Okay.

410
00:21:32,000 --> 00:21:37,000
So now we have position of the player and inside I want to make a couple of booleans, so I'm going

411
00:21:37,000 --> 00:21:44,000
to be ball player ahead, which means player going to be in front of the enemy and this will be equals

412
00:21:44,000 --> 00:21:51,000
to player transform from position that X bigger than transform position that x.

413
00:21:52,000 --> 00:21:54,000
There is also another one ball.

414
00:21:55,000 --> 00:21:57,000
Player fire away.

415
00:21:57,000 --> 00:22:00,000
Which means we have some distance between enemy and the player.

416
00:22:00,000 --> 00:22:09,000
And we're going to set it to Victor, to the distance between player transfer position and transfer

417
00:22:09,000 --> 00:22:09,000
position.

418
00:22:09,000 --> 00:22:14,000
And if distance is bigger than, let's say, six, then it means we are already far away.

419
00:22:15,000 --> 00:22:16,000
Okay.

420
00:22:16,000 --> 00:22:23,000
So now we're going to make if statement if player ahead, we're going to check if player is far away.

421
00:22:23,000 --> 00:22:29,000
So if player is far away, then we can set move speed to some high value.

422
00:22:29,000 --> 00:22:33,000
So move speed equals to, let's say, 19.

423
00:22:33,000 --> 00:22:34,000
I don't know.

424
00:22:34,000 --> 00:22:35,000
This is pretty high.

425
00:22:36,000 --> 00:22:40,000
Else, we're going to set more speed to 16.

426
00:22:40,000 --> 00:22:43,000
So he's kind of fast, but not really fast.

427
00:22:43,000 --> 00:22:45,000
And again, this is just random values.

428
00:22:45,000 --> 00:22:47,000
We can adjust them if we want to.

429
00:22:47,000 --> 00:22:52,000
Now, if player is not ahead, if player is behind, then we should slower the character and if he's

430
00:22:52,000 --> 00:22:55,000
behind and far away, we should make him really slow.

431
00:22:55,000 --> 00:23:04,000
So if player fire away, then let's set move speed to maybe like 11 and else move speed.

432
00:23:04,000 --> 00:23:05,000
We can say it.

433
00:23:05,000 --> 00:23:09,000
We can set something like 14.

434
00:23:09,000 --> 00:23:13,000
So I suppose that average speed of the player is 15.

435
00:23:13,000 --> 00:23:15,000
And according to that, I'm making these changes.

436
00:23:15,000 --> 00:23:21,000
Now let's add this function to update speed controller and back in Unity, I'm going to set up a straight

437
00:23:21,000 --> 00:23:24,000
platform, switch on my player and try to run.

438
00:23:27,000 --> 00:23:31,000
I'm going to go to prefab, find the level pirate with a straight platform.

439
00:23:32,000 --> 00:23:36,000
Make it longer like that.

440
00:23:37,000 --> 00:23:41,000
I'm going to go back, find little generator, drag this part to the generator.

441
00:23:42,000 --> 00:23:43,000
Wait, Let me unlock the inspector.

442
00:23:43,000 --> 00:23:45,000
So, little generator.

443
00:23:47,000 --> 00:23:48,000
Mellow Part six.

444
00:23:49,000 --> 00:23:52,000
Now player is switched on and we can go and check this.

445
00:23:53,000 --> 00:23:57,000
So now they are like, you know, kind of running next to each other.

446
00:23:58,000 --> 00:24:02,000
And in a moment, we all see that my player is faster.

447
00:24:10,000 --> 00:24:11,000
What is of why they are not.

448
00:24:12,000 --> 00:24:12,000
I can.

449
00:24:12,000 --> 00:24:13,000
I cannot get it.

450
00:24:15,000 --> 00:24:16,000
They have basically the same speed or what?

451
00:24:17,000 --> 00:24:18,000
Did they do something wrong?

452
00:24:19,000 --> 00:24:21,000
Oh, I did not save the script.

453
00:24:21,000 --> 00:24:21,000
My bad.

454
00:24:21,000 --> 00:24:23,000
We should save the script.

455
00:24:24,000 --> 00:24:26,000
Okay, now let's try again.

456
00:24:29,000 --> 00:24:35,000
So he small speed is 11 and I'm catching up to him and.

457
00:24:36,000 --> 00:24:37,000
Now I am close enough.

458
00:24:37,000 --> 00:24:40,000
So speed was higher and I need some more speed to get him.

459
00:24:41,000 --> 00:24:44,000
And once I'm getting really fast.

460
00:24:45,000 --> 00:24:46,000
Come on.

461
00:24:46,000 --> 00:24:52,000
Most of the player is 18 oh 20 and move speed of the enemy is.

462
00:24:54,000 --> 00:24:54,000
13.

463
00:24:54,000 --> 00:24:56,000
So I can say, Oh, I can.

464
00:24:57,000 --> 00:25:01,000
So now I cut him and we can see he's getting faster.

465
00:25:01,000 --> 00:25:04,000
We maybe could give him even more speed if he's really far behind.

466
00:25:05,000 --> 00:25:06,000
Let's try this.

467
00:25:06,000 --> 00:25:11,000
If he's if player is ahead and player is really far.

468
00:25:11,000 --> 00:25:15,000
Let's give him 21 so he can be faster than the player, maybe even 22.

469
00:25:15,000 --> 00:25:16,000
Just want to check this.

470
00:25:24,000 --> 00:25:24,000
All right.

471
00:25:24,000 --> 00:25:25,000
This looks good.

472
00:25:25,000 --> 00:25:28,000
Kind of fair, I guess.

473
00:25:34,000 --> 00:25:34,000
There is.

474
00:25:34,000 --> 00:25:36,000
My enemy can see his speed.

475
00:25:37,000 --> 00:25:40,000
Or can this little generator.

476
00:25:41,000 --> 00:25:41,000
Okay.

477
00:25:42,000 --> 00:25:51,000
Some of speed 1622 1622 So he can get in distance but not close enough and he's kind of behind And if

478
00:25:51,000 --> 00:25:55,000
I'll face something like bump into something, it's going to be different.

479
00:25:58,000 --> 00:25:59,000
Okay, this is good.

480
00:25:59,000 --> 00:26:02,000
If you want to adjust it more, feel free to play with these values.

481
00:26:02,000 --> 00:26:04,000
I think this is okay for now.

482
00:26:04,000 --> 00:26:08,000
Now let's see his behavior on the entire scene, on the arena.

483
00:26:08,000 --> 00:26:10,000
I'm going to play some level parts.

484
00:26:11,000 --> 00:26:16,000
No generator going to a place like level part one load Part five.

485
00:26:16,000 --> 00:26:18,000
You might have different parts.

486
00:26:18,000 --> 00:26:19,000
Doesn't really matter.

487
00:26:21,000 --> 00:26:23,000
We're going to see how he behaves.

488
00:26:27,000 --> 00:26:28,000
Where is the enemy?

489
00:26:30,000 --> 00:26:32,000
So I would say he's doing pretty fine.

490
00:26:36,000 --> 00:26:37,000
Right.

491
00:26:37,000 --> 00:26:38,000
This looks good.

492
00:26:40,000 --> 00:26:41,000
Yeah.

493
00:26:42,000 --> 00:26:42,000
Um.

494
00:26:45,000 --> 00:26:46,000
What else?

495
00:26:46,000 --> 00:26:51,000
Now we want him to appear, and we want him to run only for some distance.

496
00:26:51,000 --> 00:26:55,000
Because if he is living for too long, I don't want him to collect all of the coins for the player.

497
00:26:55,000 --> 00:26:59,000
So after he ran some distance, he could stop.

498
00:27:00,000 --> 00:27:03,000
Let's go and make a couple of variables.

499
00:27:03,000 --> 00:27:09,000
So first, going to be serialized field, private float distance to run, and then we just need private

500
00:27:09,000 --> 00:27:11,000
float max distance.

501
00:27:11,000 --> 00:27:12,000
All right.

502
00:27:12,000 --> 00:27:15,000
At the start, we're going to take transform position.

503
00:27:15,000 --> 00:27:16,000
Wait.

504
00:27:16,000 --> 00:27:26,000
At the start, we're going to take max distance is equals to transform position X plus distance to run.

505
00:27:26,000 --> 00:27:32,000
And then in the update over here, we're going to say if transform.

506
00:27:36,000 --> 00:27:40,000
Position at X bigger than max distance then we're just going to do.

507
00:27:40,000 --> 00:27:44,000
Can move balls and you're not going to run anymore.

508
00:27:45,000 --> 00:27:46,000
Let's go and try this.

509
00:27:46,000 --> 00:27:49,000
Going to set distance to run to something like 50.

510
00:27:49,000 --> 00:27:51,000
And I want to see this.

511
00:27:53,000 --> 00:27:54,000
Come on, boy.

512
00:27:54,000 --> 00:27:55,000
To this away.

513
00:27:55,000 --> 00:27:59,000
He is like flying that much when he's next to the ledge.

514
00:27:59,000 --> 00:28:00,000
Look, look.

515
00:28:00,000 --> 00:28:01,000
What is it?

516
00:28:02,000 --> 00:28:03,000
Oh, my God, man.

517
00:28:03,000 --> 00:28:04,000
What are you trying to do?

518
00:28:05,000 --> 00:28:09,000
He's supposed to be able to jump only if he sees the ground.

519
00:28:09,000 --> 00:28:14,000
But at the moment, I see him jumping, and it is happening because he's detecting the wall.

520
00:28:14,000 --> 00:28:24,000
So what we need to do here to fix it is to go back and just type here another curly brackets then.

521
00:28:26,000 --> 00:28:29,000
Take this is grounded and move it below.

522
00:28:29,000 --> 00:28:33,000
So I'm going to just delete it and type here.

523
00:28:33,000 --> 00:28:41,000
If is grounded, then we can apply this code and basically this is just a jump method so we can extract

524
00:28:41,000 --> 00:28:44,000
it to make it more understandable.

525
00:28:44,000 --> 00:28:45,000
Extract.

526
00:28:46,000 --> 00:28:46,000
Method.

527
00:28:47,000 --> 00:28:48,000
Jump.

528
00:28:48,000 --> 00:28:49,000
So now.

529
00:28:51,000 --> 00:28:57,000
Jump has its own condition and we can jump, if not ground forward or will detect detected.

530
00:28:58,000 --> 00:29:01,000
Let's take this check edge and speed controller.

531
00:29:03,000 --> 00:29:05,000
Let's take all of these three.

532
00:29:05,000 --> 00:29:06,000
Move them above.

533
00:29:07,000 --> 00:29:11,000
And here we can just try to return after we stop movement.

534
00:29:11,000 --> 00:29:11,000
Good.

535
00:29:11,000 --> 00:29:13,000
Let's try to run together now.

536
00:29:14,000 --> 00:29:18,000
Going to give him a distance of around maybe 150 and see how it looks.

537
00:29:19,000 --> 00:29:21,000
And now we only need to make him appear.

538
00:29:21,000 --> 00:29:22,000
And that's it.

539
00:29:31,000 --> 00:29:32,000
Is collecting my coins.

540
00:29:32,000 --> 00:29:34,000
It's giving me no chance, basically.

541
00:29:35,000 --> 00:29:36,000
You know, this is better.

542
00:29:39,000 --> 00:29:40,000
I don't see him.

543
00:29:40,000 --> 00:29:41,000
Where is he?

544
00:29:44,000 --> 00:29:44,000
All right.

545
00:29:44,000 --> 00:29:46,000
I want to adjust this by a bit.

546
00:29:46,000 --> 00:29:48,000
I want to make him faster when he's behind.

547
00:29:49,000 --> 00:29:53,000
And I want to make distance less, like two or three so we can see him.

548
00:29:53,000 --> 00:29:54,000
Let's try.

549
00:29:55,000 --> 00:29:57,000
Let's try 2.5 know, 2.5.

550
00:29:57,000 --> 00:30:01,000
And regarding the speed, let's see if player is ahead and far away.

551
00:30:01,000 --> 00:30:04,000
Let's give him more so he will catch faster.

552
00:30:04,000 --> 00:30:10,000
So maybe, I don't know, 25 and if player is ahead, but not far away, let's try 17.

553
00:30:10,000 --> 00:30:11,000
I don't know.

554
00:30:11,000 --> 00:30:12,000
So I guess.

555
00:30:12,000 --> 00:30:16,000
And if player is behind and far away, we're going to move slower.

556
00:30:16,000 --> 00:30:17,000
Yeah.

557
00:30:17,000 --> 00:30:18,000
This is okay.

558
00:30:18,000 --> 00:30:21,000
Now, regarding his appearance, basically the enemy itself is done.

559
00:30:21,000 --> 00:30:23,000
We can wrap it up and make it as a prefab.

560
00:30:23,000 --> 00:30:25,000
So let's go and do this.

561
00:30:25,000 --> 00:30:27,000
We can wrap it up and make it as a prefab.

562
00:30:27,000 --> 00:30:31,000
I only want to make him appear in a cool way, just like in the trailer you saw.

563
00:30:31,000 --> 00:30:39,000
So for this one I need to find animations and make new animation for him.

564
00:30:39,000 --> 00:30:41,000
There is a cool animation of a combat ground.

565
00:30:41,000 --> 00:30:42,000
This one.

566
00:30:42,000 --> 00:30:44,000
So let's go to animator.

567
00:30:46,000 --> 00:30:47,000
Of the enemy.

568
00:30:47,000 --> 00:30:48,000
Give me a second.

569
00:30:51,000 --> 00:30:54,000
And I'm going to make a new clip.

570
00:30:55,000 --> 00:30:56,000
And you know what?

571
00:30:56,000 --> 00:31:00,000
I'll just name it as layer because we're using layers animations.

572
00:31:00,000 --> 00:31:05,000
So why not layer ground slam?

573
00:31:06,000 --> 00:31:08,000
We're going to take these animations.

574
00:31:08,000 --> 00:31:09,000
Put them here.

575
00:31:10,000 --> 00:31:11,000
Let me see them.

576
00:31:11,000 --> 00:31:12,000
Where is the enemy?

577
00:31:14,000 --> 00:31:19,000
I'm going to try to set a sample rate to 15 and supposed to be like, boom.

578
00:31:20,000 --> 00:31:21,000
I like it.

579
00:31:22,000 --> 00:31:23,000
Boom, boom, boom.

580
00:31:26,000 --> 00:31:26,000
All right.

581
00:31:27,000 --> 00:31:34,000
Now we're going to go to animator and set this animation as default set as default.

582
00:31:34,000 --> 00:31:34,000
Good.

583
00:31:34,000 --> 00:31:38,000
So when he appears, he's going to be in this animation.

584
00:31:38,000 --> 00:31:39,000
And then.

585
00:31:48,000 --> 00:31:52,000
Maybe we should take this sprite and make it as a lending animation.

586
00:31:52,000 --> 00:31:53,000
This would be better.

587
00:31:53,000 --> 00:31:54,000
So.

588
00:31:55,000 --> 00:32:02,000
These sprites we're going to delete and make create a new clip player.

589
00:32:03,000 --> 00:32:04,000
Slam lending.

590
00:32:06,000 --> 00:32:07,000
Hey, let's take this.

591
00:32:07,000 --> 00:32:09,000
Place them here.

592
00:32:09,000 --> 00:32:10,000
Separate 15.

593
00:32:10,000 --> 00:32:13,000
So this whole engine looks good.

594
00:32:13,000 --> 00:32:13,000
Better.

595
00:32:13,000 --> 00:32:17,000
Now let's go to animator, make a grand slam by default.

596
00:32:17,000 --> 00:32:20,000
Then we're going to make transition to landing.

597
00:32:20,000 --> 00:32:21,000
If is grounded.

598
00:32:22,000 --> 00:32:23,000
Is grounded.

599
00:32:24,000 --> 00:32:25,000
Sorry.

600
00:32:25,000 --> 00:32:26,000
Condition is grounded.

601
00:32:26,000 --> 00:32:27,000
True.

602
00:32:27,000 --> 00:32:30,000
Exit time and check Duration zero.

603
00:32:31,000 --> 00:32:37,000
And then we make transition to idle move with the exit time of one transition Duration zero.

604
00:32:37,000 --> 00:32:38,000
Very well.

605
00:32:38,000 --> 00:32:43,000
And maybe we should make an event that will allow player to move once he finished the slam.

606
00:32:43,000 --> 00:32:48,000
So let's click add event here and go make a bit of a functionality to the enemy.

607
00:32:49,000 --> 00:32:50,000
First of all.

608
00:32:51,000 --> 00:32:53,000
Let's make this function that we're going to use later.

609
00:32:55,000 --> 00:32:59,000
Private void any nation trigger.

610
00:32:59,000 --> 00:33:00,000
It's going to.

611
00:33:02,000 --> 00:33:03,000
And is going to return.

612
00:33:03,000 --> 00:33:05,000
Can move through.

613
00:33:10,000 --> 00:33:15,000
Okay, we have the event and now let's go to start and give him a bit of a velocity at the start.

614
00:33:15,000 --> 00:33:17,000
So he flies up.

615
00:33:19,000 --> 00:33:25,000
Just going to be RB velocity equals to new vector to RB velocity dot.

616
00:33:26,000 --> 00:33:26,000
No.

617
00:33:27,000 --> 00:33:30,000
Well, actually, let's give it a bit of velocity index as well.

618
00:33:30,000 --> 00:33:31,000
RB Velocity.

619
00:33:31,000 --> 00:33:32,000
New vector to.

620
00:33:33,000 --> 00:33:36,000
Five on the X and maybe 12 on the Y.

621
00:33:37,000 --> 00:33:38,000
All right.

622
00:33:38,000 --> 00:33:40,000
There's going to be cool, I'm telling you.

623
00:33:41,000 --> 00:33:45,000
So that's what we need and we're going to set can move to faults by default.

624
00:33:45,000 --> 00:33:46,000
Let's go back.

625
00:33:47,000 --> 00:33:52,000
Set it to false here, then take slam lending.

626
00:33:52,000 --> 00:33:55,000
In the end, we're going to choose.

627
00:33:56,000 --> 00:34:00,000
Animation trigger, which allows this enemy to move.

628
00:34:00,000 --> 00:34:02,000
And now if I.

629
00:34:03,000 --> 00:34:05,000
Make him as a prefab.

630
00:34:07,000 --> 00:34:11,000
And then I'm going to delete them from scene and go to game mode.

631
00:34:16,000 --> 00:34:16,000
And place him.

632
00:34:16,000 --> 00:34:19,000
He's going to appear something like this.

633
00:34:19,000 --> 00:34:20,000
Wait a second.

634
00:34:21,000 --> 00:34:22,000
Not as I planned.

635
00:34:23,000 --> 00:34:24,000
Let me try again.

636
00:34:29,000 --> 00:34:30,000
Oh, I know what is happening.

637
00:34:30,000 --> 00:34:33,000
We need to do one more additional condition.

638
00:34:34,000 --> 00:34:35,000
Yeah.

639
00:34:35,000 --> 00:34:41,000
So the deal is we transferring from any state to jump fall and default state player Grand Slam is also

640
00:34:41,000 --> 00:34:42,000
any state.

641
00:34:42,000 --> 00:34:44,000
So we transfer it from this state immediately to jump fall.

642
00:34:44,000 --> 00:34:46,000
And that's why that animation is not working.

643
00:34:46,000 --> 00:34:49,000
We have two choices, as I see now.

644
00:34:49,000 --> 00:34:55,000
Either one is to use can move boolean or another one create new boolean and actually let's make a new

645
00:34:55,000 --> 00:34:57,000
Boolean so we know what is it about.

646
00:34:57,000 --> 00:35:03,000
It's going to be just respond, I'm going to copy this name so I won't forget it.

647
00:35:03,000 --> 00:35:04,000
Or is it?

648
00:35:05,000 --> 00:35:13,000
Going to copy this now From any state to jump fall, we can go only if just respond is false.

649
00:35:13,000 --> 00:35:14,000
All right.

650
00:35:14,000 --> 00:35:15,000
Very good.

651
00:35:16,000 --> 00:35:17,000
Same goes for ledge climb.

652
00:35:17,000 --> 00:35:19,000
Actually, let's do this.

653
00:35:20,000 --> 00:35:22,000
Just respond false.

654
00:35:22,000 --> 00:35:23,000
Just to protect our self.

655
00:35:25,000 --> 00:35:26,000
Yeah.

656
00:35:26,000 --> 00:35:32,000
Now let's go to code and make a boolean private bool.

657
00:35:32,000 --> 00:35:33,000
Just respond.

658
00:35:34,000 --> 00:35:37,000
Which is true by default.

659
00:35:37,000 --> 00:35:42,000
And then once we set him free, once he can run in the animation trigger.

660
00:35:42,000 --> 00:35:44,000
So we have to change this by a bit.

661
00:35:45,000 --> 00:35:47,000
Again, I said, just respond.

662
00:35:48,000 --> 00:35:48,000
False.

663
00:35:48,000 --> 00:35:51,000
So now he's not just respond and we can proceed.

664
00:35:51,000 --> 00:35:56,000
And also we need to assign animator of this boolean so anim.

665
00:35:57,000 --> 00:36:05,000
Said ball of just respond to just respond save this and let's go into unity now.

666
00:36:11,000 --> 00:36:16,000
Can I click, pause, enter play mode and drag one enemy to the scene.

667
00:36:19,000 --> 00:36:20,000
And.

668
00:36:23,000 --> 00:36:23,000
Boom.

669
00:36:24,000 --> 00:36:25,000
That was almost perfect.

670
00:36:25,000 --> 00:36:27,000
The only problem is animation was looped.

671
00:36:27,000 --> 00:36:29,000
Let's go and try to fix it.

672
00:36:29,000 --> 00:36:33,000
Animation player Grand Slam.

673
00:36:35,000 --> 00:36:35,000
Here it is.

674
00:36:35,000 --> 00:36:37,000
Loop time and check.

675
00:36:37,000 --> 00:36:40,000
And let's do the same for Slam London.

676
00:36:41,000 --> 00:36:42,000
When I try again.

677
00:36:48,000 --> 00:36:49,000
Boom.

678
00:36:49,000 --> 00:36:51,000
Okay, now let me try with the pause.

679
00:36:53,000 --> 00:36:54,000
Boom.

680
00:36:55,000 --> 00:36:57,000
Och, Och.

681
00:36:57,000 --> 00:37:02,000
To make him a bit more floaty, we can set his gravity scale to a bit lower value.

682
00:37:02,000 --> 00:37:06,000
And once his velocity is below y we're going to make it back to default.

683
00:37:06,000 --> 00:37:09,000
And if you're going to fall faster, well let's just do this improvement.

684
00:37:09,000 --> 00:37:10,000
Why not?

685
00:37:11,000 --> 00:37:15,000
Private float Default gravity scale.

686
00:37:15,000 --> 00:37:20,000
Then in the start over here, I'm going to do default.

687
00:37:20,000 --> 00:37:24,000
Gravity scale equals store B gravity scale.

688
00:37:24,000 --> 00:37:28,000
Then RB gravity scale equals to RB gravity scale.

689
00:37:28,000 --> 00:37:35,000
Let's multiply it by maybe 0.6 F, So it's going to be on the 60% of gravity scale and in the update.

690
00:37:36,000 --> 00:37:47,000
If just respond and rb velocity that y less than zero then rb gravity scale equals to default gravity

691
00:37:47,000 --> 00:37:48,000
scale.

692
00:37:50,000 --> 00:37:51,000
Yeah.

693
00:37:51,000 --> 00:37:53,000
Now, this will make him a bit more flirty.

694
00:37:53,000 --> 00:37:57,000
And while we are on this, let's make him appear at certain situations.

695
00:37:57,000 --> 00:37:59,000
So how are we going to do this?

696
00:37:59,000 --> 00:38:00,000
Super simple.

697
00:38:00,000 --> 00:38:06,000
We're going to make an empty box collider which will generate enemy when player enters it.

698
00:38:06,000 --> 00:38:08,000
So I'm going to make it empty.

699
00:38:09,000 --> 00:38:13,000
It's going to be enemy respawn.

700
00:38:17,000 --> 00:38:18,000
Position.

701
00:38:18,000 --> 00:38:19,000
All right.

702
00:38:19,000 --> 00:38:21,000
We're going to add Box Collider to it.

703
00:38:21,000 --> 00:38:21,000
So.

704
00:38:21,000 --> 00:38:24,000
Box Collider to DX is going to be a trigger.

705
00:38:24,000 --> 00:38:28,000
We're going to make it really high so Player won't miss it in any case.

706
00:38:29,000 --> 00:38:31,000
Now we're going to make create empty.

707
00:38:32,000 --> 00:38:35,000
Respond position and we need a script for this.

708
00:38:35,000 --> 00:38:39,000
Let's go New script Enemy Creator.

709
00:38:42,000 --> 00:38:43,000
Enemy creator.

710
00:38:43,000 --> 00:38:46,000
And for this we need a couple of things.

711
00:38:46,000 --> 00:38:50,000
We need serialized field, private game object.

712
00:38:52,000 --> 00:39:01,000
Game object enemy prefab and sterilized field private transform respond position.

713
00:39:02,000 --> 00:39:07,000
Then we need a function to make him and we're going to just do on trigger enter to D if.

714
00:39:09,000 --> 00:39:14,000
Collision dot get component of the layer not equals to null.

715
00:39:15,000 --> 00:39:20,000
Then we're going to instantiate enemy prefab and respond position.

716
00:39:20,000 --> 00:39:22,000
Kryptonian Identity.

717
00:39:22,000 --> 00:39:23,000
Respond position.

718
00:39:23,000 --> 00:39:25,000
Dot position, I guess.

719
00:39:25,000 --> 00:39:25,000
Yes.

720
00:39:25,000 --> 00:39:27,000
And it's something simple.

721
00:39:27,000 --> 00:39:32,000
If you want to have a random chance of spawn in it, going to be pretty simple to do.

722
00:39:32,000 --> 00:39:37,000
Serialize field private float chance to spawn.

723
00:39:37,000 --> 00:39:48,000
And just here going to do if random range from 0 to 100 is less or equals than chance to spawn, then

724
00:39:48,000 --> 00:39:49,000
we're going to do this.

725
00:39:50,000 --> 00:39:51,000
Okay, let's go back.

726
00:39:51,000 --> 00:39:57,000
Now, in unity, we need to set up enemy and set up respond position.

727
00:39:58,000 --> 00:40:02,000
Chance to spawn is up to you, but for the testing, I'll set 9 to 9.

728
00:40:02,000 --> 00:40:04,000
So it is very high chance.

729
00:40:04,000 --> 00:40:09,000
And we can make it as a prefab and use it later just to place it in the scene where you want to make

730
00:40:09,000 --> 00:40:10,000
an enemy.

731
00:40:10,000 --> 00:40:18,000
If to be precise, you need to place it on the level part somewhere, let's say here and then here,

732
00:40:18,000 --> 00:40:19,000
something like that.

733
00:40:20,000 --> 00:40:21,000
Let's go and try this.

734
00:40:23,000 --> 00:40:23,000
Oh.

735
00:40:24,000 --> 00:40:25,000
My bad.

736
00:40:25,000 --> 00:40:28,000
Let's take this enemy response position.

737
00:40:28,000 --> 00:40:30,000
Click is trigger and Click override.

738
00:40:30,000 --> 00:40:31,000
Apply all.

739
00:40:32,000 --> 00:40:33,000
Now try again.

740
00:40:36,000 --> 00:40:38,000
He's there.

741
00:40:40,000 --> 00:40:42,000
Oh, they're really fast.

742
00:40:42,000 --> 00:40:43,000
Oh, my God.

743
00:40:43,000 --> 00:40:44,000
Look at them.

744
00:40:44,000 --> 00:40:44,000
They're crazy.

745
00:40:50,000 --> 00:40:51,000
I know.

746
00:40:51,000 --> 00:40:53,000
They're so crazy.

747
00:40:53,000 --> 00:40:57,000
I noticed they jumping out, but they're just at one place.

748
00:40:57,000 --> 00:41:03,000
So what I want to do here is to set their velocity on the X to bigger value once they created so maybe

749
00:41:03,000 --> 00:41:07,000
to ten and 15 on the Y.

750
00:41:07,000 --> 00:41:09,000
And let's try this again.

751
00:41:09,000 --> 00:41:10,000
It looks cool, right?

752
00:41:10,000 --> 00:41:12,000
They're like crazy ninjas who are trying to catch you.

753
00:41:13,000 --> 00:41:13,000
My God.

754
00:41:18,000 --> 00:41:19,000
Why are they not getting any velocity?

755
00:41:19,000 --> 00:41:20,000
The x?

756
00:41:20,000 --> 00:41:21,000
I don't like it.

757
00:41:22,000 --> 00:41:23,000
Oh I know why.

758
00:41:23,000 --> 00:41:24,000
I know why.

759
00:41:24,000 --> 00:41:24,000
Och.

760
00:41:26,000 --> 00:41:29,000
Here is the deal in the movement function.

761
00:41:29,000 --> 00:41:36,000
If can move is false, then we set velocity to zero and because of that they cannot move even in the

762
00:41:36,000 --> 00:41:37,000
start.

763
00:41:37,000 --> 00:41:42,000
So what we can do is actually they move with the start, but then next frame they set velocity to zero

764
00:41:42,000 --> 00:41:42,000
and they cannot move.

765
00:41:42,000 --> 00:41:46,000
So what we can do here is to set if just respond.

766
00:41:48,000 --> 00:41:49,000
Then in return.

767
00:41:50,000 --> 00:41:51,000
Right.

768
00:41:51,000 --> 00:41:52,000
Right.

769
00:41:54,000 --> 00:41:58,000
And maybe here we can set just respond to false.

770
00:41:58,000 --> 00:42:05,000
So this will stop their x velocity when they going down, which looks well, we can see how it looks.

771
00:42:05,000 --> 00:42:06,000
Let's try this and test.

772
00:42:09,000 --> 00:42:15,000
Now we should not stop x velocity because it looks weird and also stops boolean of the animator.

773
00:42:15,000 --> 00:42:16,000
Let's delete this.

774
00:42:16,000 --> 00:42:22,000
Now, just in case I want to do something here, I want to select this enemy and change his layer to

775
00:42:22,000 --> 00:42:24,000
a new layer of the enemy.

776
00:42:25,000 --> 00:42:26,000
Enemy.

777
00:42:26,000 --> 00:42:36,000
Now I want to go to edit project settings, find physics two D collision matrix and find enemy and check

778
00:42:36,000 --> 00:42:38,000
with enemy and then check with player.

779
00:42:38,000 --> 00:42:41,000
And actually we can then check with the trap so they won't collide.

780
00:42:41,000 --> 00:42:42,000
Never.

781
00:42:43,000 --> 00:42:44,000
All right.

782
00:42:45,000 --> 00:42:49,000
Even between each other supposed to improve the feel.

783
00:42:52,000 --> 00:42:53,000
I think they could fall faster.

784
00:42:55,000 --> 00:42:56,000
And we could make it.

785
00:42:56,000 --> 00:42:57,000
We could.

786
00:43:01,000 --> 00:43:07,000
We could make RB gravity scale to default grade scale multiplied by two, let's say.

787
00:43:07,000 --> 00:43:09,000
So it's twice more of a gravity.

788
00:43:09,000 --> 00:43:16,000
They're going to fall really fast and at the trigger of the animator because set it back to default

789
00:43:16,000 --> 00:43:20,000
or B gravity scale equals to default gravity scale.

790
00:43:21,000 --> 00:43:22,000
When I see this now.

791
00:43:28,000 --> 00:43:29,000
Now there slide in there.

792
00:43:29,000 --> 00:43:31,000
I can see their slide in.

793
00:43:35,000 --> 00:43:36,000
A he can stop.

794
00:43:36,000 --> 00:43:38,000
He can stand on top of me.

795
00:43:38,000 --> 00:43:40,000
Y y he can do that.

796
00:43:40,000 --> 00:43:43,000
We did exclude it from the layers, right?

797
00:43:44,000 --> 00:43:45,000
Did they override it?

798
00:43:45,000 --> 00:43:49,000
They should be enemy on the enemy.

799
00:43:54,000 --> 00:43:55,000
Okay.

800
00:43:55,000 --> 00:43:59,000
Now they are not colliding, but they are sliding when they hit the ground.

801
00:44:00,000 --> 00:44:01,000
Don't like it.

802
00:44:03,000 --> 00:44:05,000
So let's add a bit more functionality.

803
00:44:05,000 --> 00:44:06,000
Why not?

804
00:44:07,000 --> 00:44:09,000
Just going to just respond.

805
00:44:09,000 --> 00:44:10,000
We do.

806
00:44:12,000 --> 00:44:13,000
This.

807
00:44:17,000 --> 00:44:19,000
And if.

808
00:44:20,000 --> 00:44:24,000
Is grounded, then RB velocity equals to a new vector.

809
00:44:24,000 --> 00:44:26,000
Two is zero zero.

810
00:44:26,000 --> 00:44:27,000
Like that.

811
00:44:29,000 --> 00:44:31,000
Now, this is the final step.

812
00:44:31,000 --> 00:44:34,000
Now, you know, to make it now you know how to place it on the level.

813
00:44:34,000 --> 00:44:39,000
I hope you did like this video as a bonus, content was fun to make it.

814
00:44:40,000 --> 00:44:42,000
Yeah, this looks better.

815
00:44:42,000 --> 00:44:43,000
Look, they slam.

816
00:44:45,000 --> 00:44:47,000
And they collecting all my coins.

817
00:44:53,000 --> 00:44:54,000
So destructible.

818
00:44:54,000 --> 00:44:58,000
Well, you should know that we have a lot of them here because we are testing.

819
00:44:58,000 --> 00:45:02,000
But in the game you can set lower chance and make them spawn.

820
00:45:02,000 --> 00:45:04,000
Not so often it's going to be better.

821
00:45:09,000 --> 00:45:11,000
Look at them catching you up.

822
00:45:11,000 --> 00:45:11,000
Whoa!

823
00:45:13,000 --> 00:45:13,000
It is crazy.

824
00:45:13,000 --> 00:45:16,000
And they stopped because of the distance.

825
00:45:17,000 --> 00:45:18,000
All right.

826
00:45:19,000 --> 00:45:23,000
The last issue I can see here, when they fall in, they're not dying.

827
00:45:23,000 --> 00:45:30,000
It can happen because he stopped his movement and he's very far away from the player platform, disappeared

828
00:45:30,000 --> 00:45:35,000
and he goes down endlessly and potentially we could have thousands of enemies created and stay in there.

829
00:45:35,000 --> 00:45:38,000
So and the place we created them.

830
00:45:38,000 --> 00:45:40,000
Let's do something different here.

831
00:45:40,000 --> 00:45:53,000
We can do Game object new enemy equals to instantiate and then destroy new enemy within, let's say,

832
00:45:53,000 --> 00:45:55,000
60 seconds, right?

833
00:45:55,000 --> 00:45:55,000
Why not?

834
00:45:56,000 --> 00:45:59,000
And this object, enemy creator are going to be destroyed with the level part.

835
00:45:59,000 --> 00:46:00,000
So it's fine.

836
00:46:00,000 --> 00:46:02,000
So in a 60 seconds, we're going to destroy them.

837
00:46:02,000 --> 00:46:03,000
Maybe even less.

838
00:46:03,000 --> 00:46:05,000
Maybe just 30 seconds.

839
00:46:05,000 --> 00:46:06,000
I think it's okay.

840
00:46:06,000 --> 00:46:07,000
Yeah.

841
00:46:07,000 --> 00:46:09,000
Once again, thank you for completing the course.

842
00:46:09,000 --> 00:46:15,000
I guess it was pretty big journey for you, like 12 hours or something of the content and you did it.

843
00:46:15,000 --> 00:46:16,000
You made a game.

844
00:46:16,000 --> 00:46:17,000
Very nice.

845
00:46:17,000 --> 00:46:18,000
I'm proud of you, man.

846
00:46:18,000 --> 00:46:20,000
Proud of me for creating it.

847
00:46:21,000 --> 00:46:23,000
And keep in touch.

848
00:46:23,000 --> 00:46:26,000
You can text me messages, you can type, especially if you like.

849
00:46:26,000 --> 00:46:28,000
You can write comments on YouTube.

850
00:46:28,000 --> 00:46:32,000
It would help me a lot and subscribe to my YouTube and do it.

851
00:46:32,000 --> 00:46:33,000
Do it.

852
00:46:33,000 --> 00:46:34,000
Just do it.

853
00:46:34,000 --> 00:46:35,000
I'm going to show it to you.

854
00:46:36,000 --> 00:46:39,000
Baron is supposed to be the very good channel.

855
00:46:39,000 --> 00:46:44,000
I, I try hard on it, except at the time when I'm creating courses.

856
00:46:44,000 --> 00:46:46,000
When I'm creating courses, I'm not posting videos here.

857
00:46:46,000 --> 00:46:51,000
As of now, I'm creating this RPG game, trying to make it cool and nice.

858
00:46:51,000 --> 00:46:52,000
Yeah.

859
00:46:52,000 --> 00:46:56,000
So subscribe to the channel, leave the comments there, ask you questions if you need to.

860
00:46:56,000 --> 00:46:58,000
Thank you for purchasing the course.

861
00:46:58,000 --> 00:47:03,000
Check out links in the description for promotional prices and I'll see you later.

862
00:47:03,000 --> 00:47:04,000
Bye.

