1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:03,000
In this video, we're going to finalize our slide ability.

3
00:00:03,000 --> 00:00:08,000
And actually, we need to make a fix that will make slide useful at all because now we don't have a

4
00:00:08,000 --> 00:00:09,000
point of using it.

5
00:00:09,000 --> 00:00:10,000
Right.

6
00:00:10,000 --> 00:00:16,000
So supposed to be you can slide under the platform, but at the moment, if you try to do that, let

7
00:00:16,000 --> 00:00:18,000
me let me create the situation.

8
00:00:19,000 --> 00:00:22,000
So I'll take it here and place it somewhere here.

9
00:00:22,000 --> 00:00:23,000
Yeah.

10
00:00:23,000 --> 00:00:28,000
So if I'll try to slide under, I can see I'm not going under the platform.

11
00:00:28,000 --> 00:00:30,000
And why is that happening?

12
00:00:30,000 --> 00:00:34,000
That is happening because of the collider.

13
00:00:34,000 --> 00:00:35,000
So you can see.

14
00:00:37,000 --> 00:00:39,000
We can see my collider is really big.

15
00:00:39,000 --> 00:00:49,000
And if you remember shape of the object defined not by the sprite over here, not by the sprite, but

16
00:00:49,000 --> 00:00:50,000
by the collider.

17
00:00:52,000 --> 00:00:57,000
So what we can do about this is something very simple and easy to do.

18
00:00:57,000 --> 00:01:00,000
Let's go to player animations.

19
00:01:00,000 --> 00:01:01,000
Find.

20
00:01:02,000 --> 00:01:03,000
Idle.

21
00:01:03,000 --> 00:01:05,000
And we're going to zoom it in.

22
00:01:07,000 --> 00:01:11,000
And first we want to record size of the collider how it's supposed to be.

23
00:01:11,000 --> 00:01:17,000
So when the first frame of the idle animation played, we're going to return the size of the collider

24
00:01:17,000 --> 00:01:20,000
how it was before or how we set it to be.

25
00:01:20,000 --> 00:01:26,000
So let's click this record button and to make it record any changes, we actually need to change something,

26
00:01:26,000 --> 00:01:28,000
but I don't want to change the values.

27
00:01:28,000 --> 00:01:31,000
So what I want to do here is to make.

28
00:01:32,000 --> 00:01:38,000
Size on the X, let's say 1.1 and then return it to one.

29
00:01:38,000 --> 00:01:41,000
So one and now we recorded one.

30
00:01:41,000 --> 00:01:43,000
Now we need to record this one as well.

31
00:01:43,000 --> 00:01:45,000
I'll change it and I'll change it back.

32
00:01:46,000 --> 00:01:50,000
And we want to fix that.

33
00:01:50,000 --> 00:01:51,000
I guess it's fine.

34
00:01:51,000 --> 00:01:52,000
It's okay.

35
00:01:52,000 --> 00:01:53,000
Let it be like that.

36
00:01:54,000 --> 00:01:56,000
Now we need to record offset as well.

37
00:01:56,000 --> 00:02:02,000
So it's zero and for the y89.

38
00:02:02,000 --> 00:02:05,000
So now value is the same and they are recorded over here.

39
00:02:06,000 --> 00:02:09,000
Let's click this record button that is done.

40
00:02:09,000 --> 00:02:12,000
So now if we go to.

41
00:02:13,000 --> 00:02:15,000
And let's say other animation.

42
00:02:16,000 --> 00:02:17,000
And change the collider.

43
00:02:17,000 --> 00:02:21,000
Or even if we change it now, let's try to do that.

44
00:02:21,000 --> 00:02:21,000
I'll.

45
00:02:23,000 --> 00:02:25,000
I'll decrease size on the X like that.

46
00:02:26,000 --> 00:02:33,000
Now, look, when I'll hit the play mode, I'll enter my idle animation and collider size will be changed

47
00:02:33,000 --> 00:02:34,000
to what we said before.

48
00:02:35,000 --> 00:02:36,000
Boom.

49
00:02:36,000 --> 00:02:37,000
You can see that right?

50
00:02:38,000 --> 00:02:40,000
Now, we can do the same with a slide.

51
00:02:40,000 --> 00:02:42,000
Let's go to slide.

52
00:02:44,000 --> 00:02:51,000
And actually, before we do this, I feel like the slight sprite is a bit bigger than it should be.

53
00:02:51,000 --> 00:02:52,000
I don't know why I have this feeling.

54
00:02:53,000 --> 00:02:54,000
Let's.

55
00:02:55,000 --> 00:02:56,000
Let's see this.

56
00:02:56,000 --> 00:03:01,000
Let's set our slide time to 2 seconds.

57
00:03:02,000 --> 00:03:04,000
And let's try it.

58
00:03:05,000 --> 00:03:07,000
So we can see the size of the player.

59
00:03:07,000 --> 00:03:12,000
And when I press shift, it feels like he's getting bigger, right?

60
00:03:12,000 --> 00:03:18,000
And then smaller, bigger or closer, whatever you like to think about this.

61
00:03:19,000 --> 00:03:21,000
So I want to make it a bit smaller.

62
00:03:21,000 --> 00:03:30,000
And for that I'll go to graphics folder player slide and I'll select all of the sprites and I will change

63
00:03:30,000 --> 00:03:33,000
Pixel Unit from 16 to 17.

64
00:03:33,000 --> 00:03:34,000
Hit apply.

65
00:03:35,000 --> 00:03:36,000
And now in the slide.

66
00:03:38,000 --> 00:03:39,000
He is not as big as he was.

67
00:03:39,000 --> 00:03:40,000
Right.

68
00:03:40,000 --> 00:03:41,000
That.

69
00:03:41,000 --> 00:03:42,000
That looks better.

70
00:03:44,000 --> 00:03:49,000
Now let's change offset a bit because I can see he's above the ground when he's sliding.

71
00:03:53,000 --> 00:03:54,000
Yeah, he's above.

72
00:03:54,000 --> 00:04:00,000
So what we can do again, we can select these and let's try to change offset.

73
00:04:00,000 --> 00:04:01,000
But I'm not sure what it should be.

74
00:04:03,000 --> 00:04:04,000
I'll try.

75
00:04:05,000 --> 00:04:05,000
I'll try.

76
00:04:05,000 --> 00:04:06,000
27.

77
00:04:10,000 --> 00:04:11,000
Yeah.

78
00:04:11,000 --> 00:04:12,000
This looks good.

79
00:04:13,000 --> 00:04:13,000
Right.

80
00:04:15,000 --> 00:04:15,000
Yeah.

81
00:04:15,000 --> 00:04:16,000
This looks good.

82
00:04:16,000 --> 00:04:19,000
All right, so these are changes we did here.

83
00:04:19,000 --> 00:04:22,000
Pixel per unit 17, offset 27.

84
00:04:22,000 --> 00:04:24,000
Now, let's go to the player again.

85
00:04:24,000 --> 00:04:28,000
Animation slide, and we're going to.

86
00:04:30,000 --> 00:04:32,000
Uh, enter the slide animation.

87
00:04:32,000 --> 00:04:35,000
See how it's supposed to be, then change collider size.

88
00:04:36,000 --> 00:04:42,000
I'm going to put it lower over here to make it something like this.

89
00:04:42,000 --> 00:04:43,000
Oh, wait.

90
00:04:43,000 --> 00:04:44,000
I didn't record it.

91
00:04:44,000 --> 00:04:47,000
So Control Z, undo click, record button.

92
00:04:47,000 --> 00:04:48,000
This is important.

93
00:04:48,000 --> 00:04:50,000
And then we can change size.

94
00:04:51,000 --> 00:04:53,000
Going to lower it till here.

95
00:04:55,000 --> 00:04:58,000
Yeah, I think it can be a bit lower than it's.

96
00:04:58,000 --> 00:05:01,000
Yeah, I think it can be a bit lower than it's actually should be.

97
00:05:01,000 --> 00:05:04,000
So we kind of saving player from himself without him knowing it.

98
00:05:05,000 --> 00:05:07,000
Yeah, let's keep it like that.

99
00:05:07,000 --> 00:05:08,000
All right.

100
00:05:08,000 --> 00:05:09,000
And click record.

101
00:05:10,000 --> 00:05:13,000
And now I'll go to play mode.

102
00:05:14,000 --> 00:05:18,000
I'll take this platform and place it somewhere on the head level.

103
00:05:18,000 --> 00:05:23,000
Now, this will fix the issue we had, but it makes another issue that we're going to fix now.

104
00:05:23,000 --> 00:05:25,000
Let's go and see what I mean.

105
00:05:26,000 --> 00:05:30,000
Some sliding under the platform, but this is the issue now.

106
00:05:30,000 --> 00:05:35,000
I am stuck because we made the logic that makes players stand up after some time and he doesn't know

107
00:05:35,000 --> 00:05:37,000
if there is a ceiling above him.

108
00:05:37,000 --> 00:05:39,000
So how we can fix it.

109
00:05:39,000 --> 00:05:43,000
I would like you to do it as a challenge, so I'm going to explain the logic.

110
00:05:43,000 --> 00:05:46,000
You try to do it and then I'm going to show you how to do it.

111
00:05:46,000 --> 00:05:47,000
Okay?

112
00:05:47,000 --> 00:05:48,000
All right.

113
00:05:48,000 --> 00:05:51,000
So what you need to do is to make another check.

114
00:05:51,000 --> 00:05:55,000
Same as we had for the ground, but for the ceiling above his head.

115
00:05:55,000 --> 00:06:03,000
And then you make another condition in the check for slide function that says if ceiling detected,

116
00:06:03,000 --> 00:06:06,000
then we cannot exit the slide ability.

117
00:06:07,000 --> 00:06:10,000
All right, I'm going to count till three and then I'm going to show you how to do it.

118
00:06:10,000 --> 00:06:13,000
And you have time to pause the video, obviously.

119
00:06:13,000 --> 00:06:14,000
One, two, three.

120
00:06:14,000 --> 00:06:14,000
Okay.

121
00:06:16,000 --> 00:06:17,000
So let's go to player.

122
00:06:18,000 --> 00:06:18,000
Player.

123
00:06:20,000 --> 00:06:21,000
Collision info.

124
00:06:22,000 --> 00:06:24,000
We're going to create a boolean private.

125
00:06:24,000 --> 00:06:24,000
Bool.

126
00:06:26,000 --> 00:06:29,000
Ceiling detected.

127
00:06:29,000 --> 00:06:31,000
Then detected.

128
00:06:32,000 --> 00:06:33,000
And we need.

129
00:06:34,000 --> 00:06:35,000
Sterilized field.

130
00:06:35,000 --> 00:06:36,000
Sorry.

131
00:06:37,000 --> 00:06:41,000
Serialize field private float ceiling.

132
00:06:42,000 --> 00:06:43,000
Check.

133
00:06:45,000 --> 00:06:45,000
Distance.

134
00:06:45,000 --> 00:06:46,000
I hope that is correct.

135
00:06:46,000 --> 00:06:48,000
Spelling So still check distance.

136
00:06:48,000 --> 00:06:49,000
We have that.

137
00:06:49,000 --> 00:06:54,000
Now let's go to collision function over here and make it ceiling detected.

138
00:06:56,000 --> 00:07:02,000
Equals to physics to rd dot recast from transform position.

139
00:07:04,000 --> 00:07:06,000
I'm telling you, it's basically the same as a ground check.

140
00:07:07,000 --> 00:07:08,000
Let me move it here.

141
00:07:08,000 --> 00:07:12,000
So we have kind of a way to follow it.

142
00:07:12,000 --> 00:07:13,000
Yeah.

143
00:07:13,000 --> 00:07:19,000
So ceiling detected, transform position, then ground goes down, but ceiling goes up.

144
00:07:19,000 --> 00:07:21,000
So a vector to dot up.

145
00:07:22,000 --> 00:07:24,000
Then we made a variable for the distance.

146
00:07:24,000 --> 00:07:25,000
Remember?

147
00:07:25,000 --> 00:07:28,000
Ceiling check distance.

148
00:07:30,000 --> 00:07:35,000
And if you need to find long word like that and you don't want to type it like all the letters you need

149
00:07:35,000 --> 00:07:37,000
to type, you can just do like I do from time to time.

150
00:07:37,000 --> 00:07:44,000
So I know silence distance is a long word, but I know it has kind of like sea ceiling check distance

151
00:07:44,000 --> 00:07:50,000
so I can type C for sailing and then just d I for distance.

152
00:07:50,000 --> 00:07:53,000
And there is my variable selected boom.

153
00:07:53,000 --> 00:07:54,000
And then what is ground?

154
00:07:54,000 --> 00:07:58,000
So what is ground for the layer mask?

155
00:07:58,000 --> 00:08:00,000
And we're not going to see this record.

156
00:08:00,000 --> 00:08:04,000
So we need to draw it in the gizmos and in the guys must be going to do.

157
00:08:06,000 --> 00:08:11,000
These must not draw a line from transferring position to new vector to.

158
00:08:13,000 --> 00:08:17,000
It's going to be transformed position on the X, we're not going to change it.

159
00:08:17,000 --> 00:08:22,000
And on the Y, transform position y plus ceiling check distance.

160
00:08:26,000 --> 00:08:29,000
Okay, Let's go to Unity.

161
00:08:37,000 --> 00:08:40,000
We can choose the slide ability and.

162
00:08:42,000 --> 00:08:45,000
Select the sprite and now we can check the distance.

163
00:08:45,000 --> 00:08:47,000
So distance is going to be something like.

164
00:08:48,000 --> 00:08:49,000
This is OC.

165
00:08:50,000 --> 00:08:51,000
And it's okay.

166
00:08:51,000 --> 00:08:52,000
Should be fine.

167
00:08:52,000 --> 00:08:53,000
Well, let's make it one.

168
00:08:53,000 --> 00:08:54,000
Just one.

169
00:08:55,000 --> 00:08:56,000
Yeah.

170
00:08:58,000 --> 00:08:58,000
Good enough.

171
00:08:58,000 --> 00:09:03,000
Now we can go back to code, go to a check for slide function.

172
00:09:03,000 --> 00:09:04,000
Here it is.

173
00:09:05,000 --> 00:09:15,000
And if slide time counter less than zero and we need to add the condition here and not ceiling detected,

174
00:09:15,000 --> 00:09:16,000
then it slide in.

175
00:09:16,000 --> 00:09:17,000
False.

176
00:09:17,000 --> 00:09:18,000
All right.

177
00:09:19,000 --> 00:09:21,000
That's it, I guess.

178
00:09:21,000 --> 00:09:23,000
Now, let's make sure it's working.

179
00:09:24,000 --> 00:09:25,000
Going to go to play mode.

180
00:09:28,000 --> 00:09:31,000
Going to place a long platform there.

181
00:09:32,000 --> 00:09:33,000
Just like this.

182
00:09:35,000 --> 00:09:39,000
I think we might have a slight issue there, but let's let's see it first

183
00:09:42,000 --> 00:09:47,000
and I'll make it I'll make it long and I'll make this one long as well.

184
00:09:48,000 --> 00:09:49,000
And I'll choose my player.

185
00:09:49,000 --> 00:09:51,000
Slide in time, point 4 seconds.

186
00:09:51,000 --> 00:09:54,000
So this will obviously take longer than point 4 seconds.

187
00:09:54,000 --> 00:09:55,000
Let's see.

188
00:09:57,000 --> 00:09:58,000
Yeah.

189
00:09:58,000 --> 00:09:59,000
Cool, right?

190
00:09:59,000 --> 00:10:02,000
This can make an amazing game play.

191
00:10:02,000 --> 00:10:04,000
Moments like wow moments.

192
00:10:04,000 --> 00:10:09,000
Imagine you place in a platform like that that you need to slide under.

193
00:10:11,000 --> 00:10:12,000
Okay.

194
00:10:13,000 --> 00:10:19,000
And imagine it's long and you place like I know 15 coins here and you go there.

195
00:10:20,000 --> 00:10:25,000
You collecting 15 coins is such a satisfying feeling.

196
00:10:25,000 --> 00:10:28,000
I'm telling you, that's going to be awesome.

197
00:10:28,000 --> 00:10:31,000
All right, so we're basically done here.

198
00:10:31,000 --> 00:10:34,000
I only want to rearrange our code a little bit, so.

199
00:10:35,000 --> 00:10:41,000
So a collision function, actually, we're not going here so often, so we don't need it.

200
00:10:42,000 --> 00:10:45,000
Let's say that high and we can move it down.

201
00:10:45,000 --> 00:10:47,000
We can move it below other functions.

202
00:10:47,000 --> 00:10:53,000
So let's select entire function, hold up button and click arrow down to move it down like that.

203
00:10:55,000 --> 00:10:58,000
And I'm going to place it above the gizmos just like this.

204
00:11:00,000 --> 00:11:04,000
I would say same about animator controllers.

205
00:11:04,000 --> 00:11:05,000
Let's move it down.

206
00:11:09,000 --> 00:11:15,000
Are here because basically we just come here once, set something up and then forget about it.

207
00:11:16,000 --> 00:11:17,000
Then we can.

208
00:11:19,000 --> 00:11:20,000
Yeah.

209
00:11:21,000 --> 00:11:23,000
We can place check inputs.

210
00:11:25,000 --> 00:11:25,000
Yeah.

211
00:11:25,000 --> 00:11:27,000
Under the buttons, I guess.

212
00:11:36,000 --> 00:11:39,000
So now we know where the collision checks and animator controllers that we need.

213
00:11:39,000 --> 00:11:46,000
And if we need to assign some animator Bolen or add another collision, we can just go all the way down

214
00:11:46,000 --> 00:11:53,000
with the mouse or all the way down with the key page down on your keyboard like that.

215
00:11:55,000 --> 00:12:01,000
And now we know we can set collision here, animators here, input here, and then we go through our

216
00:12:01,000 --> 00:12:06,000
buttons that we have there, slide button, jump button, and then we have some movements and update.

217
00:12:07,000 --> 00:12:08,000
Okay, cool.

218
00:12:09,000 --> 00:12:12,000
Now I want to make sure we cannot jump when we do in that slide.

219
00:12:12,000 --> 00:12:19,000
Let's go and check that, because we never assigned the logic of restricting jump.

220
00:12:20,000 --> 00:12:21,000
There.

221
00:12:23,000 --> 00:12:25,000
Going to go to play mode.

222
00:12:27,000 --> 00:12:30,000
It's actually something I forgot about.

223
00:12:30,000 --> 00:12:31,000
And then I just thought about it.

224
00:12:32,000 --> 00:12:34,000
So I'll make a long platform.

225
00:12:35,000 --> 00:12:36,000
Like that.

226
00:12:36,000 --> 00:12:37,000
And another one.

227
00:12:38,000 --> 00:12:39,000
That meant.

228
00:12:40,000 --> 00:12:42,000
Let's go and then I'll try to jump.

229
00:12:43,000 --> 00:12:43,000
Yeah.

230
00:12:44,000 --> 00:12:45,000
This is ugly, right?

231
00:12:45,000 --> 00:12:50,000
Let's go to code and just change it slightly in the jump button.

232
00:12:50,000 --> 00:12:55,000
What we can do is to make if is sliding.

233
00:12:56,000 --> 00:12:58,000
Then return.

234
00:12:58,000 --> 00:13:04,000
So what return does is it makes it stop the function from where it was returned.

235
00:13:04,000 --> 00:13:10,000
Basically, if you make a metaphor about it, imagine you send in someone for work and you send in our

236
00:13:10,000 --> 00:13:12,000
function to work, right?

237
00:13:12,000 --> 00:13:14,000
And then when you say return.

238
00:13:15,000 --> 00:13:17,000
The function stops working and going back to you.

239
00:13:17,000 --> 00:13:19,000
Something like that, Yes.

240
00:13:19,000 --> 00:13:20,000
So if I chose a bad metaphor.

241
00:13:20,000 --> 00:13:21,000
I'm sorry.

242
00:13:21,000 --> 00:13:28,000
All what you need to know is when you call a return, whatever code is after the return, it won't work.

243
00:13:28,000 --> 00:13:30,000
It just won't.

244
00:13:30,000 --> 00:13:32,000
So now we're going back.

245
00:13:32,000 --> 00:13:34,000
Going to place a platform again.

246
00:13:36,000 --> 00:13:37,000
Maybe this long.

247
00:13:38,000 --> 00:13:39,000
I think as long.

248
00:13:41,000 --> 00:13:42,000
And.

249
00:13:44,000 --> 00:13:45,000
I cannot jump when I'm sliding.

250
00:13:46,000 --> 00:13:48,000
But I can do it after.

251
00:13:49,000 --> 00:13:49,000
All right.

252
00:13:50,000 --> 00:13:55,000
And since now we know about return, let's do some other changes here.

253
00:13:56,000 --> 00:14:00,000
We're going to go to the movement function and type if.

254
00:14:01,000 --> 00:14:03,000
No wall detected and wait.

255
00:14:03,000 --> 00:14:10,000
If all detected, then return and we can delete it from here so we won't clutter the update.

256
00:14:11,000 --> 00:14:14,000
The functionality is the same as just written a different way and it's okay.

257
00:14:14,000 --> 00:14:21,000
So now what we have here we send if player unlocked, then do movement and in the movement we check

258
00:14:21,000 --> 00:14:28,000
if detect it then return and there won't be any other functionality until will detected is false.

259
00:14:28,000 --> 00:14:29,000
All right.

260
00:14:29,000 --> 00:14:31,000
That's it for this video and I'll see you on the next one.

261
00:14:31,000 --> 00:14:31,000
Let's go.

