Search code examples
visual-studiounity-game-enginephysicsraycasting

Why will my physics 2D raycast not display or work correctly?


Basically i wanted to make a raycast for jumping but for some reason the distance of the raycast is wrong and never changes and the position of it is so wrong i cant even seem to find it:

    ray2D = Physics2D.Raycast(transform.position, -Vector2.up, .1f, GroundedLayers);
    Debug.Log(ray2D.distance);
    isGrounded = groundCheck();

Grounded layers do not include the player, distance always returns as 0, grounded is always false and the gizmos line only draws when i open the prefab and not at all in the scene:

enter image description here

here the distance is set to .1f but displays the same as 1f

(EDIT: ok so i checked and for some reason the raycast happens around 0, -1 even tho thats nowhere near the player transform?)

enter image description here


Solution

  • I found that the raycast was detecting an invisible trigger so i had to put it on another layer :)