Raycast2D direction

I’m just trying to use the raycast2d for the collision detection, the ray is going down, so it should work only when it falls on something, but for some reason it sets onGround to true even when it collides on the side, why it’s doing that?

EDIT : I tried adding a number to it Physics2D.Raycast(transform.position, - Vector2.up, 1), but the problem is still there.

void OnCollisionStay2D(Collision2D obj)
    // Cast a ray straight down.
    var hit: RaycastHit2D = Physics2D.Raycast(transform.position, - Vector2.up);		
	// If it hits something...
	if (hit != null) {
		onGround = true;

   void OnCollisionExit2D(Collision2D obj)

		   grounded = false;

Your Raycast() has no distance limits. So if there is anything under your character no matter what the distance, the Raycast will return a non-null value. One fix would be to add a distance parameter to the Raycast so that it only extends just beyond the bottom of the character.