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 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
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
5 People are following this question.
How do I obtain the surface normal for a point on a collider (can't use RaycastHit.normal)?
Angle between Ray and Normal
shooting raycast from each triangle on mesh and change its texture
Raycast Normal in Local Rotation?
Allow y rotation