- Home /
Question by
landon912 · Nov 27, 2012 at 11:08 PM ·
physicscolliderarraydistancephysics.overlapsphere
Get distance from all objects in an Collider[] and compare
I have been using
stockpile =Physics.OverlapSphere(transform.position,Mathf.Infinity,stockpileLayer);
to get an array of colliders hit, in a layermask. This completely works but how would I get the distance in each and store them.
Comment
Best Answer
Answer by CostelloNicho · Nov 27, 2012 at 11:26 PM
So you have an array of Colliders and your looking for the distance to each of these objects. (I'm guessing from the current transform you are working with)
Maybe something like this:
foreach( Collider collide in stockpile ){
float _dist = Vector3.Distance(transform.position,
collide.transform.position);
distanceList.Add( _dist );
}
Distance List being a list of floats to carry each of the distances from the current transform to each of the colliders in stockpile.