- Home /
Physics.raycast
Physics.Raycast(ray, out hit, 1000, 9)
Am I correct to assume that this statement translates into cast a ray against all colliders except anything that is on layer 9?
Because the behavior Im getting is that it only cast against anything in the Default layer and ignores everything else.
Answer by testure · Aug 04, 2011 at 03:55 PM
No, the layermask is a bitmask, you've passed in an integer. a bitmask makes use of the fact that binary numbers are made up of 1's and 0's, each digit in a binary number being equivalent to one bit. The binary numbers essentially act as "switches" to enable or disable certain layers.
There are plenty of other answers here on UA that go into a LOT of detail on how they work, so I won't bother with that. Although, to simplify things, have a look at the LayerMask class, it should simplify what you're trying to do.
Ive been reading this all mourning and it doesnt explain very much to me.
Next I tried Layer$$anonymous$$ask mask = 9; Physics.Raycast(ray, out hit, 1000, mask.value)
Im not understanding something.
How do I cast against everything except layer 9?
As I said, you keep giving it integer values. it wants a BIT$$anonymous$$AS$$anonymous$$. which means you have to create a layermask and bitshift it to the layer you want. Read this carefully:
http://answers.unity3d.com/questions/8715/how-do-i-use-layermasks.html
Final Answer for future reference:
To cast against everything except layer 9 use Physics.Raycast(ray, out hit, 1000, ~(1 << 9)
Your answer
Follow this Question
Related Questions
Raycasting to the bottom side of a plane? 2 Answers
Physics.CapsuleCast Help 1 Answer
Raycast stops working after ~40 seconds when target has Rigidbody 2 Answers
Is Physics.Raycast deterministic? 1 Answer
Make a rolling ball always on ground without falling when reaching the edges of the map 1 Answer