Matching Orthographic Camera Size to Perspective Camera - Unity

Matching Orthographic Camera Size to Perspective Camera


 How to do:

In Unity, you can match the size of an orthographic camera to that of a perspective camera by using the "fieldOfView" property of the perspective camera. Here is an example of how you could do this:

// Get a reference to the perspective camera
Camera perspectiveCamera = Camera.main;

// Get a reference to the orthographic camera
Camera orthographicCamera = GetComponent<Camera>();

// Set the size of the orthographic camera to match the field of view of the perspective camera
orthographicCamera.orthographicSize = perspectiveCamera.fieldOfView;


In the code above, we first get a reference to the perspective camera and the orthographic camera. Then, we use the fieldOfView property of the perspective camera to set the orthographicSize property of the orthographic camera.


The fieldOfView property of a perspective camera represents the vertical field of view, which is the angle between the top and bottom edges of the camera's view frustum. The orthographicSize property of an orthographic camera, on the other hand, represents half the size of the camera's viewport (the height of the viewport in world units). By setting the orthographicSize of the orthographic camera to the fieldOfView of the perspective camera, we ensure that the two cameras have the same vertical field of view.


Keep in mind that the resulting image from the orthographic camera may not match the image from the perspective camera exactly, as the two cameras have different projection models. However, setting the orthographicSize in this way can help you match the size of the two cameras as closely as possible.


I hope this helps! Let me know if you have any other questions