How can I fix my Raycast so it returns true when there are tiles beneath the player
13:38 02 Jun 2023

In my platformer, my player clamps onto the sides of tiles and hooks there. I want to remove this so the player can't clamp onto the sides of any tiles on my Tilemap.

In my movement script, I tried to add a Raycast that shoots downwards. I excepted it to work but instead it isn't letting me jump and is playing the falling animation which only occurs if my isGrounded variable is set to false. I am suspecting something is wrong with my Raycast.

Here is the code:

void OnCollisionEnter2D(Collision2D col)
    {
         RaycastHit hit;
        if (Physics.Raycast(transform.position, Vector3.down, out hit)) 
        {
            if (hit.collider.gameObject == floor) 
            {
                isGrounded = true;
            }
        }
  
    }

NOTE: the floor variable is the tilemap

c# unity-game-engine 2d raycasting