layer mask - bit shift?

Hello, I am trying to use a layer mask with a raycast and trying to figure it out. I have one layer, which is layer 3 in the dropdown box in the inspector. And I have that assigned in code using layerMask = 1 << 3. However I am confused by this, is this the same as bitshifting? if so wouldnt this result in 8 and not layer 3?

I am trying to create another layermask to be used with items on layer 0 in the drop down box in the inspector. How would i assign this in code?

some info on this example,

but its easier to setup layemask value in the inspector, public variable layermask (you can select none, one or multiple layers easily)

It is the same as bit shifting.
It is the number 8, but the number 8 is layer 3. it’s like this:

1 = [0001] = layer 0
2 = [0010] = layer 1
3 = [0011] = layer 0 and layer 1
4 = [0100] = layer 2
5 = [0101] = layer 2 and layer 0
6 = [0110] = layer 2 and layer 1
7 = [0111] = layer 2 and layer 1 and layer 0
8 = [1000] = layer 3

1 Like

Thank you both, was very helpful and have managed to get it working now :slight_smile: