Detect when Raycast DOESN'T hit layer.
Hello, Is there's a way to detect when a raycast doesn't hit a specific layer, and then still have the raycast object to pull coordinates from the point where the raycast occurred. Like some sort of negative raycast.
I have a layer called platforms and I want to raycast starting from a point WITHIN that layer. From there, I want to detect when the raycast hits not platforms .
Is this possible?
Thanks.
Answer by T0mC · Feb 03, 2018 at 05:05 PM
if the platform was layer 8 you'd use this to get the layer mask, ~ just negates the selection in the second line then you would use layerMask as the final parameter in the raycast
LayerMask layerMask = (1 << 8);
layerMask = ~layerMask;
Physics.Raycast(transform.position, transform.forward, Hit, Range, layerMask)
Your answer
Follow this Question
Related Questions
RayCast2D and RayDraw errors 0 Answers
2D raycast not working 0 Answers
Raycast 2d is not working at all 0 Answers
Rigidbody blocking raycasts 2D 0 Answers
Linecast ignores obstacles. 0 Answers