Detect when Raycast DOESN'T hit layer.

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?


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)