- Home /
Raycast works perfectly, but only in editor
So, I have a raycast that looks like this:
Ray ray = cachedCamera.ViewportPointToRay(new Vector3(.5f, .45f, 0));
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 500, layerToIgnore.value) && hit.point != focalPoint) {
focalPoint = hit.point;
focalPointAssigned = true;
}
So, weird time. If I use this as is in an editor build, it is perfect. If I use this as is in an actual build, it doesn't focus at all, or the focusing makes no sense (I.e. look in a weird direction and blocks suddenly focus).
But then if I remove the distance and layer mask, it works like a charm (this does not work for me, however, because I need to be able to ignore certain things).
Is this a known bug?
Going by your variable name, the layer$$anonymous$$ask is what you can hit, not what you ignore. But if that was the entire problem, it wouldn't be working in the editor either.
I think the lazy-eval inside the IF is safe.
Your answer
Follow this Question
Related Questions
Layer Mask Detection 2 Answers
Help Can't find the Correct Parameters 1 Answer
Raycast not working 2 Answers
How to make my raycast also hit deactive objects WITHOUT showing the object? 1 Answer
Layermask doesn't seem to work 2 Answers