- Home /
How to Detect the Number of times a raycast intersects a Mesh
As the title asks I need a way to use the even-odd rule algorithm and as far as I am aware raycasts in unity only allow one collision per mesh and i need a way to detect whether the player is inside a specific mesh.
you could use bounds.Contains with the player position. This will tell you if the player is inside. Now for a better result you could encapsulate the player within a cube and check for all 4 corners if they are inside. That would tell you if the player is entirely inside.
It would depend on how much accuracy you need.
http://docs.unity3d.com/ScriptReference/Bounds.Contains.html
Answer by Cherno · May 11, 2015 at 12:25 PM
You can cast a ray, and if it hits, cast another ray with the same direction, but starting at the hit.point + a tiny little amount towards the direction to ensure you are inside the mesh and don't hitz the same spot again. Repeat until you don't hit anything. This will obviously not work if you need to register a ray going "out" of a mesh (coming opposite from the face's normal dir).
Raycast doe snot detect from inside a collider.
From the doc:
Notes: Raycasts will not detect colliders for which the raycast origin is inside the collider. If you move colliders from scripting or by animation, there needs to be at least one FixedUpdate executed so that the physics library can update it's data structures, before a Raycast will hit the collider at it's new position.
Answer by barbe63 · May 11, 2015 at 01:21 PM
I found this for you:
http://answers.unity3d.com/questions/163864/test-if-point-is-in-collider.html