Unity Community

Results 1 to 12 of 12

  1. Posts

    Orthographic screen size

    I'm making a "2D" game using 3D planes and an orthographic camera.
    My base is a 640x960 screen and I want to have a 1:1 pixel in this screen size to place all my elements.
    I'm using an orthographic size of 960/2 = 480, but the width is not 640 but seems to be 720???

    1/ What can I do to get the right width?
    2/ What can I do to make the game view being the same whatever screen size is used? ( elements should be automatically scaled ).
    Last edited by Risine; 11-29-2011 at 02:12 AM.

  2. Location

    The 720 width you are getting is from multiplying the aspect ratio of the screen by the orthographic height;

    Aspect = (width / height)
    = (960 / 640)
    = 1.5

    Orthographic width = Orthographic size * aspect
    = 480 * 1.5
    = 720

    The confusion here is that Orthographic size is actually related to the height of the viewport


    So for your game you'll want to set size to (screen height / 2 )
    = 640 / 2
    = 320

    Hope that helps

  3. Posts
    Thanks SBurgess , that's "almost" clear for me.

    Just one thing I don't understand.
    If I want a width of 640, I should have :
    640 = Size * 1.5
    Size = 640 / 1.5 = 426.666 and not 320 ????

  4. Location
    Is your game screen 960 tall and 640 wide?

  5. Posts
    My game screen is width = 640 and height = 960 ( portrait )

  6. Location
    Well you were doing the right thing to start with Orthographic size of 480.

    The only reason with width would be wrong is if your not actually running the game at the screen size you thought. Is the window squashed in the editor by any chance?

  7. Posts
    Ok, seems like I was wrong positioning my background. And 480 is the value ( Screen height / 2 ). Thanks.

  8. Posts
    Oh well, here I come again on this subject, it wasn't that clear indeed after all.
    I can't find any logical equation about that :
    Let me resume :
    I place my elements based on a 640 width x 960 height (in unity units).
    I'm using an orthographic camera.
    WHAT I WANT : I want my 640 width to fit the phones screen width whatever width it is.
    my results depending on screen size :
    320x480 -> Ortho size = 480
    480x800 -> Ortho size = 530
    480x854 -> Ortho size = 560
    640x960 -> Ortho size = 440
    Does someone has an idea of the equation to get the correct ortho size depending on screen width and height?

  9. Location
    Zürich, Switzerland
    normally it would be: 640.0/screenwidth * screenheight/2

    Basically you take the normal orthogonal equation for "unity unit to pixel" (screenheight/2) and scale it by the desired 'normalized screen width' of 640 pixels which is 640/screenwidth. This gives you basically your values which you likely got from 'trial and error' search (cause it would be 533.333 for 480x800 for example or 569.xx for 480x854)

    question is why 640x960 is that seriously wrong cause that one should be 480, for all others its within the range of 10 pixels at maximum where it goes wrong (trial and error tolerance)
    Last edited by Dreamora; 12-14-2011 at 05:54 AM.

  10. Posts
    That works perfectly, thanks Dreamora.

  11. Posts
    I am having a similar issue and having trouble understanding how this should work.

    Suppose I have a background image texture which is 640width by 960 height that I would like to display pixel per pixel on the IOS 4 retina display. I imported this texture as an asset and changed the advanced option for "non power of 2" to none.

    I have set up an orthographic camera with size 5 and normalized viewport rect of
    X = 0 Y=0
    W = 1 H=1.5

    I have created a plane and added my texture to it. I then rotate the plane 90 X and 180Y so that it faces the camera.
    I scale the plane X = 1 y =1 X = 1.5

    At this point, I would hope that when I build the app, it would should show me my background exactly fit to the Iphone 4S retina display. This does not appear to work properly for me, I see most of my background but it is appears cut off from the top.

    Any thoughts on what I may be doing wrong?

    Last edited by Arachnid; 12-18-2011 at 02:36 AM.

  12. Posts
    hey Risine how should i set my project that should run on different android smartphones

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts