Ortho camera fit width


We are developing 2D games for mobiles in portrait mode. We work on sprites and use an ortho camera. The background we use look fine on smartphones but they aren’t wide enough for tablets. We are looking for a way to scale the view to fit the width of the screen, since we’re okay with cutting off a bit of the background texture’s top and bottom.

We’ve been trying to achieve that through horizontalFov in the camera settings, but turns out it applies only to perspective camera and we’re wondering if there’s any similar setting for ortho.
For now we are trying to update the orthoHeight based on the screen ratio but we’re not sure if this is the way to go.

Here’s a pic to visualise what we’d like to achieve

Any help would be appreciated, thanks!

You have orthoHeight and aspectRatio to play with. I think you need to

  • pick a value for orthoWidth you’d want to be visible
  • set aspectRatio to your screenWidth / screenHeight
  • set orthoHeight to orthoWidth / aspectRatio

so for example, if your screen is 480 x 640, and you want orthoWidth to be 1000, the aspectRatio will be 0.75 and orthoHeight will be 1333.



Thanks to the reply!
Yes I figured we would need to play with these values, can I ask why what you mean by orthoWidth ? I don’t see any properties with that name in the camera
Are you talking about “Resolution Width” field in the Rendering settings ?

orthoWidth is the size of the world you want to fix on the screen horizontaly. Not a property, just your internal variable.

Ah yes makes sense, so that’s our background width in our case
Thanks for the hints, we’ll try that next week !

1 Like

Hello, we were able to try it out last week and the formula you gave us worked perfectly, thanks again!

1 Like