Hello, guys.
So one day I received a question how to fix this trouble.
And I looked at the screenshot and I was like, Huh?
Why even this happening?
I was genuinely confused why this might happen at all.
And it took me some time, but I found why.
And now I'm going to explain why this is happening.
And what is it?
I could make same situation in my project.
Happens quite often.
But fix is pretty simple, so don't worry.
First I'll try to show you.
Yeah, I got it.
You see?
So this happened.
Why this happened.
Wait a second.
I'll try to do it again, but I'll pause the game.
So at this point.
The second.
At this point.
There is a platform inside of the Ledge checkbox.
Exactly this one.
So we are not supposed to be able to detect the ledge, if you remember, in the cold.
We said can detect true only when we exit the trigger, which is an our trigger is exactly this one
which is responsible for checking if there is any ground inside.
But we can have this kind of a behavior, this kind of bug, if at the same time we exit platform and
steal, there is another platform inside.
Let me try to.
Find this level part.
So this is one level part.
A canvas canvas is on the way a second.
So this is one level part and this is the second level part.
And.
And as you can see, they overlay in each other.
So there is one platform and there is a second platform here.
So when our box doing check our box, maybe I can change the color so it's more obvious for us.
Look.
When our books did the checking, it exited this platform.
Which is you see, it's even longer in a.
Yeah.
Got it.
I'll do it like this.
Yeah.
So when our box did the check before it entered the alleged climb animation.
It was exiting this platform and it set our can detect to true.
And then at the same time, it entered another trigger over here.
Which set?
Can detect a false, but because it happened within one frame, it was enough time to set players ledge
detected to true because it was detected even though we exited one trigger at the same time there was
another trigger.
So what we need to do is to make sure there is no platforms at all in the trigger before we set can
detect to true over here.
For that, we're going to get access to a box.
Collider we have.
Exactly this box.
Collider So we know the size and position of this box.
Collider.
No matter how we change it, exactly, this box.
Collider So what I'm going to do is go to ledge the ActionScript close all but this.
I'm going to create a private box collider to D, which I will name Box Seed.
As for Box Collider, and I don't want to type any start function, I'll just do return get component
of box Collider to DD.
So now this box seed is this box.
Collider Exactly, this one.
What I'm going to do next is before I set can detect to true, I'm going to check if there is any ground
at all in this trigger.
And we're going to go to on trigger exit to the we're going to create a bunch of colliders that are
going to be that are that are going to be a temporary values collider to the.
Colliders.
And this means we created a colliders just like basically the very same we did here.
But it's going to be used once only inside of this function and trigger exit to DX, and we need to
assign this value and we're going to assign this value because this is array.
We can put a bunch of colliders there and we're going to assign it equals to all of the colliders that
are inside of our trigger, right?
So how are we going to do this?
We're going to do colliders equals to physics to DX, overlap box.
Box all.
Box seed bounce that center box seed that size and angle are going to be zero.
After that, we're going to do check for each collider inside.
So we're going to do for each.
And here we're going to do var Heat in colliders.
Then what are we going to check?
We're going to check if heat means the collider that we hit inside of the box.
Game object get component of platform controller because all of them has this component.
So I'm going to use this one as a check.
If you remember this, the one that responsible for changing colors.
Right.
So if it has this component.
Then we're going to return.
And this means we do in check inside of the box.
Collider Basically, we're doing check of all of the boxes from center point of our box.
Collider This one.
Within the size of our box Collider Again, this one.
So you can change the size of it.
It doesn't matter.
It will always take the size.
We set.
And then we see if there is any object in it.
We're going to check it.
And if this object has platform controller, then we're going to return from this function.
And it means we not going to set can detect a true, pretty simple.
And in this way we're not supposed to meet any similar bug to this again.
Now, let me try this.
I saved my script.
If you remember, I did catch this bug somewhere here because there were two platforms together.
Let me switch off the canvas.
One platform and this is the second one.
So they overlay in each other.
Yeah.
I'll try to find this bug in my game.
I'm sure it won't be there because I did check it before recording.
So no such bug.
Okay.
I hope that explains why that was happening and how to fix it.
Now you know how to fix it.
Maybe I should do it in the first place.
But it was quite, quite difficult to debug this.
I wouldn't face this issue by myself, I guess, unless somebody pointed out.
Thank you for that.
Also, thank you for paying attention.
Finish the course.
Check my other courses.
They're pretty cool and I'll see you in the next one.