Raycast always hit

Hi, I’m trying to make a double jump using Raycast. Sounds pretty simple, but for a reason my raycast hit all the time, and returns true even if there’s nothing else in the scene and I’d like to know why.

Here is my code :

public class CharacterControls : MonoBehaviour {

    private Rigidbody2D _rb;
    [SerializeField]
    private float _speed;
    [SerializeField]
    private float _jumpForce;

    private Collider2D _coll;

void Update()
    {

        Debug.Log(Grounded());
        
        if (Grounded())
        {
            Debug.Log("Grouded");
        }
        else
        {
            Debug.Log("Oh Oh");
        }

bool Grounded()
    {
        return (Physics2D.Raycast(transform.position,Vector2.down,_coll.bounds.extents.y + 0.1f));
    }
}

What I’m trying to acheive is that the raycast goes down, with a distance just a bit lower than the collider. For a reason though, even if there is no ground, nothing else than the character in fact, Grounded() is always true. More than that, I can put any distance I want, even negative ones, and it will be true. What I’m doing wrong?

Thanks for the help!

The Physics2D system works different than the 3d Physics system. The Physics2D.Raycast method actually returns a RaycastHit2D struct. So checking if the struct is “null” / can be converted to bool makes no sense.

See the example on the Raycast documentation page i’ve linked. You have to check if the “collider” reference in the hit structure is null or not.