- Home /
What does bounds.sqrdistance do?
I've read the unity manual on bounds.sqrdistance and I'm confused. It says "The smallest squared distance between the point and this bounding box." Can anyone help to explain this a little bit more clearly?
Thanks
Answer by dan_wipf · Jan 18, 2019 at 07:35 AM
Ok Bounds.SqrDistance(Vector 3 point) is equal for example to this:
float SmallestDistance = Vector3.Distance(Vector3_Point,GetComponent<Renderer>().bounds.ClosestPoint(Vector3_Point));
float BoundsSqrDistance = SmallestDistance * SmallestDistance;
so to be clear. Bounds.SqrDistance(Vector3 point) does makes a new Square between the closest Point of a Boundary Box and a given Vector3 point and as Result you get a Distance² float between the closest Point of a BB and a given Vector3 point.
So you could break it down to get the actual distance, if you'd do a Square Root √ Mathf function like this:
float acutal distance = Mathf.Sqrt(GetComponent<Renderer>().Bounds.SqrDistance(point);
Let me know if this is the kind of Wisdom you've searched for.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do I get the square root of a double number value? 2 Answers