Question by
TrackOdin · Jan 28, 2021 at 01:59 AM ·
collision2d game2d-platformerjumpingground detection
How can I fix this with my ground check?
So if I use a second collider, to check that the player is grounded or not, then if the collider has the same width as the player, then I can jump up on walls. If the collider's width is smaller, then I can't jump at the very edge of the platform. How should I make it then? Is there any way to fix this?
Comment
Best Answer
Answer by hamerilay · Feb 03, 2021 at 01:08 PM
Make a bool called "onGround".
Then in your OnCollisionEnter use this:
Vector3 normal = collision.GetContact(0).normal;
if (normal == Vector3.up)
{
onGround = true;
}
In your OnCollisionExit use this:
onGround = false;
and in your Start use this:
onGround = true;
This will check if the player hit the top side of the object it hit and only then set "onGround" to true.
Now before you jump check if "onGround" is equal to true.