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