Search Unity

2D is on ground check providing false positives

Discussion in 'Physics' started by CJ-Clark, Nov 3, 2018.

  1. CJ-Clark

    CJ-Clark

    Joined:
    Jun 26, 2013
    Posts:
    4
    Hello, I'm writing a simple Mario-like game using RigidBodies. I'm struggling to properly detect if I am on the ground, due to floating point inaccuracy. Does anyone have ideas based on the below information? If so, thank you, it's been years of various approaches to this, none have yet worked.

    When the player stands against a ledge and jumps up past it and falls, they fall and hit the ground properly. I have a function that checks under the player to see if they are on the ground, it does a shape cast down using the same box on the player as a bounds. While falling, Unity shows no intersection via OnCollisionEnter, however my function to see if they are on the ground hits the ledge due to floating point inaccuracies.

    Another issue that's related, if I jump and tap towards the ledge so I would land a couple pixels on the ledge, Unity pushes me off the ledge as the collision resolution instead of resolving the collision with me landing ON the ledge like I should. All tunings in PhysicsManager and the RigidBody's don't seem to affect this at all.

    Here's my original post for more information and a picture.
    https://answers.unity.com/questions/1566479/2d-isonground-check-providing-false-positives.html