- Home /
Distance between a point and any point on an object
i presume vector3.distance will just give me the distance between the origin of an object and the point but i need the closest distance between them.. what would be an efficient way of doing this?
thanks
If the object has a collider and a "normal" shape, you can get a pretty good idea by raycasting. I don't know of a perfect solution. Even comparing all the vertices of the mesh has some issues.
many objects have obscure shapes so im using mesh colliders on all objects.. checking all verts seems pretty expensive..
I've never done this so you'll probably get a better method or explanation from someone else. I'm thinking you should be able to cache all verts and create a lookup table. Iterating through that should be really fast. Something similar to the A* algorithm.
I don't know if this gets you any closer:
Collider.ClosestPointOnBounds().
It won't be as accurate as checking the vertices.
that seems like it might do what i want. doesnt have to be exact..