- Home /
Cube shaped mesh collider side detection
Is there a way to detect which one of six sides was hit by raycast?
Answer by hexagonius · Oct 11, 2018 at 08:03 PM
The largest absolut value of either x y or z of the hit point vector should tell you which side. For example when Mathf.Abs(y), with y = -5, returns 5 and is the largest value, you know it's the bottom.
Answer by BastianUrbach · Oct 12, 2018 at 10:28 PM
Use raycastHit.normal, which gives you a unit vector perpendicular to the face that was hit. So for example, if you hit the left face of an axis aligned cube, you get Vector3.left.
I think this may not work for shapes like rhombus 3D but I find working solution. I'm creating for each surface plane then shoot 2 Ray's, one for plane second for collider. If plane hit.point == collider hit.point I found correct face.
Why not? It should work for all convex shapes. Alternatively, you can also use the triangle index or the texture coordinates of the RaycastHit.
Your answer
![](https://koobas.hobune.stream/wayback/20220612180152im_/https://answers.unity.com/themes/thub/images/avi.jpg)