Hello, guys.
Currently in the game, we have an issue that we need to fix and it will be a target of this video.
So at the moment, if I'll take my platform and turn it into a wall just like that and place it somewhere
in front of character and then I'll run, we can see that when facing the wall, he's doing transition
between idle and move animation endlessly, and it looks like a bug, but it's not like a bug.
It's more of a misbehavior I would say that we did not fix yet, so this would be going to do how we
can fix it.
We could just check if there is anything in front of the character and if there is, then we're going
to stop.
Or if to be more precise, we're not going to move anymore.
All right.
How we can do that?
We could do it with a check saying what we did for the ground.
Check this one.
You remember this check?
We could make another check from the head of the player, let's say, to the right side to see if there
is a wall.
But that leaves us with an issue.
What if we face in not a wall like that, but a platform about half the size of the player?
And if check is like that and there is still something, you're going to keep running like that.
Okay, We could make another check from the feet of the player just like that.
So at this point we would detect the platform.
But what if what if it would be a very slim platform, let's say a platform of this size?
And we have a check from his head, from his feet.
So now what?
We need to make another check from here.
Then again, then again, then again, then again.
And at this point, you can see it's kind of look like a box in front of the character.
So what we can do is to use box cast to check if there is in front of the check, if there is anything
in front of us.
Basically, we're going to draw a box of somewhat this size.
And if any wheel gets into this box, then we're going to stop movement.
All right, let's do that.
And I want to begin with simple.
I want to draw that box with the gizmos, and then we're going to set the logic.
All right.
What do we need to do?
Let's go to gizmos over here, type gizmos, draw a wire cube and you can see we need a center and we
need a size of the box.
So we're going above to collision info over here, creating serialized field private transform.
That's going to be a center position for the box.
So we'll check, I'll name it, we'll check.
And we need the size and we're not working in 3D, as you remember.
We work in into this space so we can use vector two for the size of the box.
We'll check size.
All right.
And while we are here, let's create a boolean.
Well, sorry.
Well, Detective.
Okay.
Now let's go all the way down.
And here we're going to type.
We'll check that position.
And for the size, we'll check size.
Now let's go back to Unity.
Oh, and sorry, I had this object from testing, but don't worry.
I'm going to show you how to make it.
So let's create an empty under the player and just name it as well.
Check.
All right, Now we're going to select the player and drag ball check to this field.
Now let's set the world check size to 1 to 1.
And by dragging this wall.
Check this one.
Sorry.
We can place it somewhere.
And now if we move a player, it will move together with a player because it is child of the player
and player.
It's parent.
So it kind of has this position, right, no matter how he moves.
Now when adjust the size of it.
So we don't need it so wide because if it's going to be very wide, let's say of this size, then layer
will detect all and this point.
Right.
And he'll stop and there will be empty space between him and the wall, not what we need so we can make
it slim.
Something like 0.5.
And regarding the height, let's try it two and we need to make sure it's above ground level.
So maybe somewhere here I go.
Should we make it higher?
Let's make it 2.25 and place it here.
And later, if we need, we can always fix it.
But now I just want to make sure it's not detected in the ground.
Let's go there.
And it does not.
It is above the ground, right?
Yeah.
By the way, a player is also above the ground.
Why is that?
Because of the collider.
Actually, it's not a big deal, right?
It's not noticeable, but I'll try to.
Yeah, it's better.
Pixel perfect, I would say.
But now my offset and size is messed up.
So point nine here and two point.
Point 4 to 7 of the height.
Yeah.
Let's do this.
Zero nine and 2.2.427.
Here I changed the size and offset the bit here.
To make it precise.
Okay, back to business.
Let's go to player now and in the check collision here we're going to do all detected equals to physics
to DX and guess what we need here?
Box cast.
Now you can see what it requires to work.
We need origin, size, angle, direction, and it's going to be easy to set up.
Let's do origin world check dot position for the size world check size.
Now?
ENGEL We don't need to change it.
So zero direction.
We don't need to change it.
So.
Vector 2.0.
Distance zero.
And now layer mask.
What is ground?
We have that.
Now let's go to player unlocked and just make another condition here and not well detected.
So this movement will be applied if player unlocked and there is no will detect it.
Very simple to do very efficient.
Let's go and see this in the action.
Take the platform and place it in front.
Somewhere.
And I'll try to face it.
Boom!
Stopped.
If I'll try another one this summer.
Lower.
Stopped.
For now we have a slight issue that we need to fix and.
I'm going to show you what I mean right now.
So look, if I'll go to jump State and I'll do double jump.
Now, Michael, double jump is false.
And if you remember, we're making it true only at the moment of jump from the ground over here.
Right.
And because of that, we cannot transfer to jump full state.
And because of that, when I'm going off the platform without pressing jump, you can see I'm still
doing it in the idle mode state.
I am working on the air.
We have an easy fix for this and I don't see the reason not to use it now.
If we need to change it later, we always can do it.
But for now I'm just going to cut out.
Can double jump through from here.
And I'm going to go to update.
And just like if is grounded.
Then can double jump through.
That's it.
Now let's go and see if it works.
It's supposed to work.
And just need long platform in front of the character.
So now I'll do a double jump and do it again and I go off the platform in a full state.
Perfect.
Perfect, perfect.
Now there is something else we could do.
Let me see.
How long is the video?
It's okay.
Something else we could do to help us in the future.
It is to put this movement in function.
Let's do this.
And let's select the line click alt enter to call submenu and extract method.
And I'm going to call it.
Movement.
All right.
Now, at this point, we have a movement function and if we want to change movement behavior, somehow
we can do it in this function and we want the clutter update too much.
There is some more changes I want to do to this, but let's keep it for the next videos.
Don't want to clutter your head with a bunch of information.
Let's take it step by step.
So let's go to the next video.