Search Unity

Physics2D.Raycast LayerMask not working!?

Discussion in '2D' started by inewland, Nov 17, 2013.

  1. inewland

    inewland

    Joined:
    Dec 6, 2012
    Posts:
    20
    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?

    Code (csharp):
    1. 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...
     
  2. alotko

    alotko

    Joined:
    Nov 13, 2013
    Posts:
    1
    I'm having the same issue. Any luck debugging this?
     
  3. Edvard-D

    Edvard-D

    Joined:
    Jun 14, 2012
    Posts:
    129
    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?
     
  4. honigkuchen

    honigkuchen

    Joined:
    Nov 24, 2013
    Posts:
    7
    You need to bitshift the layermask like this...
    Code (csharp):
    1. 1 << LayerMask.NameToLayer("Environment")
     
    Eldoir, zenlove and acorrow like this.