Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Adjusting camera to view entire mesh bounds?

Discussion in 'Scripting' started by seon, Sep 19, 2008.

  1. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    I would like to set my Camera's Orthographic size to the extent of the bounds of a combined mesh, to ensure that the camera will ALWAYS show all of the mesh in the camera view, no matter what resolution the user selects.

    For instance, my level geo is (90.9, 0.0, 54.1) in size (y is ignored because camera is looking down)... I need to set my :-

    Code (csharp):
    1. Camera.main.orthographicSize = XXX;
    ...to fit it all in.

    Any ideas? Please?
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Well, orthographicSize is the half-size of the camera's view "up and down". You haven't stated what the rotation is while looking down so I'll offer a simpler version:

    Your level geo is 50 x 50, your orthographicSize is 25 (the size you set is the half-height).

    In your case I'd play it safe and suggest taking the larger of the two values (90.9) and divide it in half to get 45.45.

    Both of those offer an exact fit though, so you may want to tweak that (increase the size specified) by a touch to get a little padding if that's of interest. And in the second case you'll likely need some information about how the camera is rotated while looking down as well as your viewport's aspect ratio to be sure you can fit in all in. In both of my cases I'm assuming the viewport is wider than it is tall.


    Does any of that get you closer?
     
    Ruslank100 likes this.
  3. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Hey Tom,

    Thanks for that little bit of info.. yes that has helped me keep everything looking right! at different resolutions!

    Thanks :)