Unity3D Correct Orthographic Size of Camera

11,911

First scale the cameras transform to 2/screenHeight, so if you have 1920x1080 screen it should be 2/1080

Then set your cameras orographic size to 1

Then on the sprite, set the "pixels to units" to the height of the image size, so if you have a image of size 128x128 the pixels to units should be 128

Now if you place your sprite as a child to your camera, the scale of the object will be in pixels. so if you want a sprite of size 128x128 to be 128x128 on a 1080 screen just set the scale of the transform to 128,128,0

The bonus of doing it this way is that you design the game for one resolution like 1920x1080 and when you run it on a screen with another resolution (same aspect ratio) you just need to change the 2/screenHeight for the camera and everything will have the same relative size which will make it look the same as long as the aspect ratio is the same.

Share:
11,911
Namely
Author by

Namely

Updated on June 04, 2022

Comments

  • Namely
    Namely almost 2 years

    For 2D game, default camera(orthographic) size is 5 and I am trying to figure out what it should be to get original views of images. What should it be? Because 5 shows the images very smaller than original size.

  • MalachiteBR
    MalachiteBR about 9 years
    What about other aspect ratios? Do you have any idea on how to make the game looks identical on every aspect ratio ?
  • Imapler
    Imapler about 9 years
    The short answer is that you cant. There are only more or less bad ways to hide the fact that you change the aspect ratio. One simple way is to make it for a small aspect ratio like 4:3 then add black bars on the side, thus keeping the 4:3 for the view port. Another way is simply allow someone with wider aspect ratio to see more the someone with a narrow.