Physics2D.Raycast LayerMask not working!?

Hi all,
Has anyone been able to get Layer Masks working for the new 2D Physics? Not having any luck here… am I missing something?

RaycastHit2D hit2d = Physics2D.Raycast(ray2d.origin, ray2d.direction, 1, LayerMask.NameToLayer("Environment"));

P.S. Getting collisions to work just fine when no mask is defined…

I’m having the same issue. Any luck debugging this?

What exactly is happening that makes you think it’s not working? Are you getting errors for that line alone, or do the issues come up later?

You need to bitshift the layermask like this…

1 << LayerMask.NameToLayer("Environment")
3 Likes