Hi, I’m new at Unity3d forum,
I have already looked for this question all over the internet, but I can’t find a solution!
In Unity I have my First Person Controller with its camera that can move all over the terrain.
On my scene there are some objects and I would like to do this:
when the user click on an object, the camera should move to the object and should go away or walk up from the object to let user see all the entire object!
At the moment I’m able to center the view on the object (with LookAt), but I don’t know how to move the camera away from the object!
Is there the possibility to know camera and object dimension to then calculate the distance to set between them?
Perhaps someone knows how to do this magically in Unity. I do not.
But it’s basically right triangle math. You need to know the height and width of the object relative to the player. You need to know the viewing angle (height and width) to see the edge of the object. As you stated, you are trying to figure out the distance, which will be the greater distance calculated using the height and width of the object.
This is what I thought, but without dimensions I can’t make the calculation!
Hovewer, I have found a possible solution: using a collider, I could calculate the dimension by collider.bounds.center and collider.bounds.extents! I will try with these 2 coordinate to calculate the dimension of the object!!!