- Home /
RaycastAll/RaycastHit - select "outermost" collider among nested colliders?
It seems RaycastAll/RaycastHit provides an array of collider hits in no particular order.
I'm wondering how I would go about ordering them say from innermost to outermost for a group of nested colliders? Or, more simply, just select the "outermost".
Please note I have no target in mind. The outermost could be gameObject A,X,alpha,Bob,Tom, etc. I'm not looking to identify a hit by name or tag.
I imagine one could test for distance to the camera (assuming the camera is outside the "outermost" collider). Wondering if there is a simpler approach.
thanks
Answer by Mike 3 · Jun 13, 2010 at 04:19 PM
I would order them by the lowest value of Vector3.Distance(startOfRay, hit.point)
On top of that, I'd just write a simple IComparable implementation so that you can just simply use yourArray.Sort(comparer) and it'll sort it in very few lines of code
Your answer
![](https://koobas.hobune.stream/wayback/20220613062024im_/https://answers.unity.com/themes/thub/images/avi.jpg)