Ground Check Issue
So ive been following the 2d controllers tutorial and he was covering the groundcheck and falling physics. The problem im having is that when the player is not on ground, the ground boolean does check off but the groundcheck dont let the player fall off at all. Please help!
Answer by Konomira · Oct 11, 2015 at 03:16 PM
If you are using a rigidbody and colliders, you can easily check if you're touching the ground by adding a "ground" tag to your ground object, then adding this:
void OnCollisionEnter2D(Collision2D col)
{
if (col.collider.tag == "ground")
{
grounded = true; // the object is touching the ground
}
}
Then to check if the object is no longer touching the ground, you just insert this:
void OnCollisionExit2D(Collision2D col)
{
if (col.collider.tag == "ground")
{
grounded = true; // the object is no longer touching the ground
}
}
void OnCollisionEnter2D() and OnCollisionExit2D trigger automatically when two colliders either touch, or stop touching.
Thanks for teh extra info but i need to fix the issue where my player doesnt fall off a surface even the ground bool works properly with the ground check. Like i followed the 2d controllers tutorial correctly and my Player still walks on air :(.