- Home /
Point mesh shortest vector
What is the best way to find the shortest vector between a point and a mesh? The only way that I can think of is iterating through 360° and steps in a secondary angle, creating a vector from the two angles, and using raycast.
Answer by hvilela · Sep 30, 2012 at 02:31 AM
Add a MeshCollider to your mesh and use Collider.ClosestPointOnBounds.
Vector3 closest = collider.ClosestPointOnBounds(point);
Vector3 resultVector = closest - point;
Hola,
ClosestPointOnBounds gives you the closest point ......... on the bounds. (the bounding box.)
Unfortunately often it is useless when you need to literally find the closest point on a mesh.
It is often very, very, VERY .... VERY ... difficult mathematically and programmatically to truly find the closest point on a mesh to a given random point.
In true video game engineering, the solution always depends on the very specifics of the situation, and finding an optimized way to do so.
This is a well-travelled and much suffered problem in simulations and other aspects of game production.
Your answer
![](https://koobas.hobune.stream/wayback/20220613081646im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why is raycast not working with mesh collider 0 Answers
Rendering part of the mesh 0 Answers
Mesh Collider Issue(?) - Raycast (ScreenPointToRay) Appears to Collide on Nothing 0 Answers
Detecting the subobject of a mesh 1 Answer
Are tag settings passed down from Game Object parent to mesh child? 1 Answer