Top Down Perspective Camera FOV to Orthographic size

Hi

I have a perspective camera with an fov of 60.
It looks at an object from top view with a rotation(90, 0, 0) and position (0, 50, 0)

The user has the option to change the camera to orthographic view to get a 2D view without any depth from top

Now how can i calculate the orthographic size so the view looks same as that in the perspective view(just not having the depth)?

so the view looks same as that in the
perspective view

That’s not possible at all since an orthographic projection and a perspective projection are entirely different. The only thing that can be kept the same is the size at a specific depth, any other depth will change the appearance.

So what you can do is calculate the frustum height at a certain distance and use that for the orthographic size. Note that the orthographicSize specifies half the screen height. So you would have to do:

Camera cam = Camera.main;
var halfFrustumHeight = desiredDistance * Mathf.Tan(cam .fieldOfView * 0.5f * Mathf.Deg2Rad);
cam.orthographicSize = halfFrustumHeight;

The result would be like this, just without the smooth transition once you switch between perspective and orthographic projection. Keep in mind that only the specifed distance (desiredDistance) will keep it’s size on screen.

Hi @Bunny83 thanks for answering this. The code snippet itself was easy to understand because your naming convention is excellent.