- Home /
Physics.Raycast - Not Hitting Backside of Mesh/Poly?
I have a case where theres a building which has no interior, and I want to check how far down my character is after animation a "vault over fence". The problem is, that after the animation the characters location is slightly "below" the surface of the building.
I've noticed that doing a raycast down works fine from above the surface, but in the case above my raycast upwards finds - nothing! Even though there clearly is a plane above them.
So my question is if there is a setting to ensure that raycasts consider the plane from both sides? Is this happening because the backside is being culled and so unity3d considers this off the table for raycast hits?
Answer by Eric5h5 · Jun 04, 2011 at 08:43 PM
It's not possible to make raycasts check both sides. If you need both sides to be hit, then you have to model both sides.
Answer by Leith_Ketchell · Mar 01, 2018 at 09:01 AM
You can enable Physics.queriesBackFaces (added in Unity 5.5)
Answer by Bunny83 · Jun 05, 2011 at 03:28 PM
All primitive colliders have no "interior". It's the default concept how nearly all collision systems work. Only if you use a non convex meshcollider and like Eric said you've modeled both side you can collide with both sides. Convex mesh colliders behave like every other primitive collider, so there are no "backfaces".
In your case you could start your raycast with an offset. Just shift the starting point upwards say 1.0. If you want to "measure" the distance you have to subtract the offset from the returned distance.
But watch out: The resulting distance can be negative (since you are slightly below the surface). Also keep your offset as small as possible. If you offset it 10m you will hit the second floor inside a building :D