- Home /
How to get distance between camera and object?
I want to get distance between camera and object. Actually, I want to get the closest vertex point of the object from the camera. (not the position or center of the object) I'm not sure how to get this.
Answer by save · Jun 04, 2013 at 12:55 PM
One way to solve it is to iterate through the vertices of the object and compare their magnitude between their TransformPoint (converts local to world space) and the camera transform. Get all vertices through the MeshFilter, loop through them and store the value at the current which has a lower magnitude.
This is what I think to do that. But, I'm not sure how to extract each vertex from $$anonymous$$eshFilter. Thanks for your help.
The $$anonymous$$esh.vertices section in the docs has an example of getting each vertex.