OverlapArea has a margin ?!?

Hello,

I’m creating my first 2D game with Unity.

In this game, the player can jump. To ensure that it jumps only when its feet touch the ground, I’ve attached 2 empty objects to the player that I’ve placed slightly under its feet.
Then, in my script, I update a bool _isGrounded like this:

    private void FixedUpdate()
    {
        _isGrounded = Physics2D.OverlapArea(groundCheckLeft.position, groundCheckRight.position);
    }

In my first atempt, _isGrounded was always set to true, even when my player was in the air.

With further investigations, I’ve realised that OverlapArea was detecting a contact with the player’s collider. Indeed, if I place the empty objects lower under the player’s feet, the problem is solved.

However, it still seems strange that OverlapArea detects a contact with the player’s collider unless I set a minimal distance between them.

Does someone know if its an expected behavior ? And, is there a way to configure that “margin” ?

Thanks

This is more so, intended behavior.

In project settings under Physics 2D you have setting called Default Contact Offset. This is set to 0.01 as default which when using a PPU of 100(also the default on sprites) that means exactly one pixel.

Now changing this to something lower will help, but it will not allow zero in that field and is also something I do not recommend changing.

To fully alleviate the problem, the best thing to do is use the physics layers to ignore the player when checking for ground below. I fully recommend that you use a ContactFilter2D instead of just layers as well, so you can fine tune how it detects ground.