using layer mask on linecast

i need to do a line cast that ignores user layer 8, labeled waypointmask, but im not sure what to put in as the peram the code is below. and in c#
i believe its supposed to be an int but i’ve tryed using 8 and this does not work

 if(Physics.Linecast(b.position, a.position, out hit,??????waypointmask???????))
 {
	do stuff 
	}

1 << 8

and btw. wrong forum.

Mm… i guess is ~1<<8 … isn’t it?

That line cast would only look in layer 8.

It’s actually:

“int.MaxValue - (1 << 8 )”

So that you get:

11111111 11111111 11111111 01111111

as your flags.

I wrote a quick explanation on bit shifting and flags here:
http://forum.unity3d.com/viewtopic.php?t=61024

Yeah, it’s a wrong forum. Could a mod please move it?

On topic:
Usually when I need to have a raycast mask, I do not use ugly 1 << N in my code, I use a public LayerMask variable and set the proper mask from there. Much easier to work with.

public LayerMask RaycastLayers;
 if(Physics.Linecast(b.position, a.position, out hit, RaycastLayers)) 
 { 
   do stuff 
   }

[/code]

1 Like