Physics2D.Raycast not detecting collider

Hello there.

Can anyone of you help me with this situation? It seems like my Physics2D.Raycast() is not working at all.

Whenever I try to Debug.Log() the name of the hit object by the raycast, I’m getting a null reference. I am using a LayerMask named “raycastMask” as my filter when raycasting. Currently it is set to “Everything”.

Information on the GameObject I’m trying to perform a raycast on:

[Layer and tag]

  • Layer: “Ground”

  • Tag: “Ground”

[Components]

  • Collider: Polygon Collider 2D

  • Rigidbody: Rigidbody2D (Kinematic)

I’ve tried to used RaycastAll(), which works (don’t know why), but I want to avoid using that.

To me, it looks like everything is fine, but its apparently not! Can anyone of you tell me what I’m doing wrong? I’ve been debugging this for like an one and a half hour now…

Also, nevermind the missing }, its there in the actual code.

Thanks!

umm, ive never tried using your math infinity statement. its unnecessary. if you just give a point and direction seperated by a comma, it assummes infinity. try that for simple raycast. thats how it always works for me :slight_smile:

give the other details later like layer and distance after you know it works. its a good way to see if its a script problem or something you are doing wrong with colliders and inspector stuff.

Omg… I found out what I was doing wrong. I was modifying the wrong Layermask Facepalm
I’m sorry for wasting your time. Thanks a lot for the answers though!

Could moderators please delete this question?