Posted in GameDev > GameDev blog
Tags: #Unity

Adjusting an ortographic camera to fit the screen width in Unity

By default, Unity will fit the height of the scene to the height of the screen, and adjust the width based on the aspect ratio. This is sometimes desirable, but sometimes it's better to have it the other way around: fit the width of the scene to the width of the screen, and adjust the height accordingly. This is very easy to achieve with an ortographic camera:

Camera.main.orthographicSize = originalOrtographicSize * (originalAspectRatio / Camera.main.aspect);

For instance, if our camera has a size of 5, and we're aiming at an aspect ratio of 16:9, the formula becomes:

Camera.main.orthographicSize = 5f * ((16f / 9f) / Camera.main.aspect);


How to parent an object to a bone in Blender 2.9

GameDev blog


It's oh, so quiet...

You must be logged in to post comments.

Want to subscribe?

Get notified by email when a new post is published.

log in | sign up

End of page. Back to page navigation.