x


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

more ▼

asked Jun 13 '10 at 03:58 PM

pickledzebra gravatar image

pickledzebra
286 31 35 44

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Jun 13 '10 at 04:19 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

Thanks Mike. Very helpful.

Jun 13 '10 at 05:03 PM pickledzebra
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x282
x161
x36
x22

asked: Jun 13 '10 at 03:58 PM

Seen: 1711 times

Last Updated: Jun 13 '10 at 03:58 PM