Search Unity

Physics.IgnoreRaycastLayer setting to water mask

Discussion in 'Scripting' started by seronni, Apr 28, 2017.

  1. seronni

    seronni

    Joined:
    Jun 25, 2015
    Posts:
    18
    Hi!

    I'm using Unity 5.6.0f3

    When I set my object layer to ignore ray cast, Unity put the water mask...

    Code (CSharp):
    1.  
    2. sphereLaserPoint.layer = Physics.IgnoreRaycastLayer;
    Then when I go to the editor my sphere is on the Water Mask, Anyone knows what happens?

    I try this too:
    Code (CSharp):
    1.  
    2. sphereLaserPoint.layer = 1 << Physics.IgnoreRaycastLayer;
    But dont find any layer with this code...
     
    Last edited: Apr 28, 2017
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
    They should definitely both work the same way. If you can post a simple project with the problem happening I can have a look for you.
     
  3. istarus

    istarus

    Joined:
    Mar 10, 2018
    Posts:
    1
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    Physics.IgnoreRaycastLayer is badly named. But if you mouseover it, you'll see that it doesn't actually reflect the layer. Instead, it reflects the layer mask of that layer. Remember that layer is not the same as layer mask.

    If you want to use that constant, you can, but you'll need to reverse the mask bitshifting back to the layer index. Something like this:

    Code (CSharp):
    1.  
    2. private static int ReverseBitShift(int mask) {
    3.         var retval = 0;
    4.         while(mask > 1) {
    5.             retval++;
    6.             mask /= 2;
    7.         }
    8.         return retval;
    9.     }
    But I'd probably just use LayerMask.NameToLayer("Ignore Raycast") instead.