- Home /
A question about "Physics.Raycast()"
I wrote my codes like this, var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; var distanceInfi = Mathf.Infinity;
if(Event.current.type==EventType.MouseDown){ if (Physics.Raycast (ray, hit, distanceInfi,8)) { firstPosition = hit.point; print(firstPosition); }
} Also,I found that there is an argument named "layermask" in function "Physics.Raycast()", so I set number 8 in my code according to my creating plane's layer is "user layer 8" . But, there is no output,I don't know why? Is there any problem?
Answer by Kryptos · Mar 20, 2012 at 05:01 PM
Layermask is not the number of the layer used but rather a bitfield made of different layer. Check the documentation for more details.
If you want to use the layer 8 inside your mask, use this code instead:
LayerMask mask = 1 << 8;
http://unity3d.com/support/documentation/Components/Layers.html
Your answer
Follow this Question
Related Questions
Is it possible to allow a raycast to pass through a collider to hit things behind it? 6 Answers
Why is Physics.Raycast returning colliders in a layer not included in the layermask? 2 Answers
Why are raycasts so unreliable? 2 Answers
RaycastHit returns object without collider, in wrong layer 1 Answer
LayerMask for RayCast 1 Answer