Hello, guys.
In this video, we're going to finalize our slide ability.
And actually, we need to make a fix that will make slide useful at all because now we don't have a
point of using it.
Right.
So supposed to be you can slide under the platform, but at the moment, if you try to do that, let
me let me create the situation.
So I'll take it here and place it somewhere here.
Yeah.
So if I'll try to slide under, I can see I'm not going under the platform.
And why is that happening?
That is happening because of the collider.
So you can see.
We can see my collider is really big.
And if you remember shape of the object defined not by the sprite over here, not by the sprite, but
by the collider.
So what we can do about this is something very simple and easy to do.
Let's go to player animations.
Find.
Idle.
And we're going to zoom it in.
And first we want to record size of the collider how it's supposed to be.
So when the first frame of the idle animation played, we're going to return the size of the collider
how it was before or how we set it to be.
So let's click this record button and to make it record any changes, we actually need to change something,
but I don't want to change the values.
So what I want to do here is to make.
Size on the X, let's say 1.1 and then return it to one.
So one and now we recorded one.
Now we need to record this one as well.
I'll change it and I'll change it back.
And we want to fix that.
I guess it's fine.
It's okay.
Let it be like that.
Now we need to record offset as well.
So it's zero and for the y89.
So now value is the same and they are recorded over here.
Let's click this record button that is done.
So now if we go to.
And let's say other animation.
And change the collider.
Or even if we change it now, let's try to do that.
I'll.
I'll decrease size on the X like that.
Now, look, when I'll hit the play mode, I'll enter my idle animation and collider size will be changed
to what we said before.
Boom.
You can see that right?
Now, we can do the same with a slide.
Let's go to slide.
And actually, before we do this, I feel like the slight sprite is a bit bigger than it should be.
I don't know why I have this feeling.
Let's.
Let's see this.
Let's set our slide time to 2 seconds.
And let's try it.
So we can see the size of the player.
And when I press shift, it feels like he's getting bigger, right?
And then smaller, bigger or closer, whatever you like to think about this.
So I want to make it a bit smaller.
And for that I'll go to graphics folder player slide and I'll select all of the sprites and I will change
Pixel Unit from 16 to 17.
Hit apply.
And now in the slide.
He is not as big as he was.
Right.
That.
That looks better.
Now let's change offset a bit because I can see he's above the ground when he's sliding.
Yeah, he's above.
So what we can do again, we can select these and let's try to change offset.
But I'm not sure what it should be.
I'll try.
27.
Yeah.
This looks good.
Right.
Yeah.
This looks good.
All right, so these are changes we did here.
Pixel per unit 17, offset 27.
Now, let's go to the player again.
Animation slide, and we're going to.
Uh, enter the slide animation.
See how it's supposed to be, then change collider size.
I'm going to put it lower over here to make it something like this.
Oh, wait.
I didn't record it.
So Control Z, undo click, record button.
This is important.
And then we can change size.
Going to lower it till here.
Yeah, I think it can be a bit lower than it's.
Yeah, I think it can be a bit lower than it's actually should be.
So we kind of saving player from himself without him knowing it.
Yeah, let's keep it like that.
All right.
And click record.
And now I'll go to play mode.
I'll take this platform and place it somewhere on the head level.
Now, this will fix the issue we had, but it makes another issue that we're going to fix now.
Let's go and see what I mean.
Some sliding under the platform, but this is the issue now.
I am stuck because we made the logic that makes players stand up after some time and he doesn't know
if there is a ceiling above him.
So how we can fix it.
I would like you to do it as a challenge, so I'm going to explain the logic.
You try to do it and then I'm going to show you how to do it.
Okay?
All right.
So what you need to do is to make another check.
Same as we had for the ground, but for the ceiling above his head.
And then you make another condition in the check for slide function that says if ceiling detected,
then we cannot exit the slide ability.
All right, I'm going to count till three and then I'm going to show you how to do it.
And you have time to pause the video, obviously.
One, two, three.
Okay.
So let's go to player.
Player.
Collision info.
We're going to create a boolean private.
Bool.
Ceiling detected.
Then detected.
And we need.
Sterilized field.
Sorry.
Serialize field private float ceiling.
Check.
Distance.
I hope that is correct.
Spelling So still check distance.
We have that.
Now let's go to collision function over here and make it ceiling detected.
Equals to physics to rd dot recast from transform position.
I'm telling you, it's basically the same as a ground check.
Let me move it here.
So we have kind of a way to follow it.
Yeah.
So ceiling detected, transform position, then ground goes down, but ceiling goes up.
So a vector to dot up.
Then we made a variable for the distance.
Remember?
Ceiling check distance.
And if you need to find long word like that and you don't want to type it like all the letters you need
to type, you can just do like I do from time to time.
So I know silence distance is a long word, but I know it has kind of like sea ceiling check distance
so I can type C for sailing and then just d I for distance.
And there is my variable selected boom.
And then what is ground?
So what is ground for the layer mask?
And we're not going to see this record.
So we need to draw it in the gizmos and in the guys must be going to do.
These must not draw a line from transferring position to new vector to.
It's going to be transformed position on the X, we're not going to change it.
And on the Y, transform position y plus ceiling check distance.
Okay, Let's go to Unity.
We can choose the slide ability and.
Select the sprite and now we can check the distance.
So distance is going to be something like.
This is OC.
And it's okay.
Should be fine.
Well, let's make it one.
Just one.
Yeah.
Good enough.
Now we can go back to code, go to a check for slide function.
Here it is.
And if slide time counter less than zero and we need to add the condition here and not ceiling detected,
then it slide in.
False.
All right.
That's it, I guess.
Now, let's make sure it's working.
Going to go to play mode.
Going to place a long platform there.
Just like this.
I think we might have a slight issue there, but let's let's see it first
and I'll make it I'll make it long and I'll make this one long as well.
And I'll choose my player.
Slide in time, point 4 seconds.
So this will obviously take longer than point 4 seconds.
Let's see.
Yeah.
Cool, right?
This can make an amazing game play.
Moments like wow moments.
Imagine you place in a platform like that that you need to slide under.
Okay.
And imagine it's long and you place like I know 15 coins here and you go there.
You collecting 15 coins is such a satisfying feeling.
I'm telling you, that's going to be awesome.
All right, so we're basically done here.
I only want to rearrange our code a little bit, so.
So a collision function, actually, we're not going here so often, so we don't need it.
Let's say that high and we can move it down.
We can move it below other functions.
So let's select entire function, hold up button and click arrow down to move it down like that.
And I'm going to place it above the gizmos just like this.
I would say same about animator controllers.
Let's move it down.
Are here because basically we just come here once, set something up and then forget about it.
Then we can.
Yeah.
We can place check inputs.
Yeah.
Under the buttons, I guess.
So now we know where the collision checks and animator controllers that we need.
And if we need to assign some animator Bolen or add another collision, we can just go all the way down
with the mouse or all the way down with the key page down on your keyboard like that.
And now we know we can set collision here, animators here, input here, and then we go through our
buttons that we have there, slide button, jump button, and then we have some movements and update.
Okay, cool.
Now I want to make sure we cannot jump when we do in that slide.
Let's go and check that, because we never assigned the logic of restricting jump.
There.
Going to go to play mode.
It's actually something I forgot about.
And then I just thought about it.
So I'll make a long platform.
Like that.
And another one.
That meant.
Let's go and then I'll try to jump.
Yeah.
This is ugly, right?
Let's go to code and just change it slightly in the jump button.
What we can do is to make if is sliding.
Then return.
So what return does is it makes it stop the function from where it was returned.
Basically, if you make a metaphor about it, imagine you send in someone for work and you send in our
function to work, right?
And then when you say return.
The function stops working and going back to you.
Something like that, Yes.
So if I chose a bad metaphor.
I'm sorry.
All what you need to know is when you call a return, whatever code is after the return, it won't work.
It just won't.
So now we're going back.
Going to place a platform again.
Maybe this long.
I think as long.
And.
I cannot jump when I'm sliding.
But I can do it after.
All right.
And since now we know about return, let's do some other changes here.
We're going to go to the movement function and type if.
No wall detected and wait.
If all detected, then return and we can delete it from here so we won't clutter the update.
The functionality is the same as just written a different way and it's okay.
So now what we have here we send if player unlocked, then do movement and in the movement we check
if detect it then return and there won't be any other functionality until will detected is false.
All right.
That's it for this video and I'll see you on the next one.
Let's go.