- Home /
 
How to adjust a 2.5D game for android for different resolutions
The game I am creating is 2D with 3D camera. From what I understand, I should instantiate every game object in my game based on the aspect ratio and not the resolution, but that doesn't sound good enough in my ears.
Also, I have no idea what to do with the camera.
Answer by kromenak · Sep 03, 2012 at 09:45 AM
In my experiences, the camera will always fill the available vertical space on the device's screen. You can imagine that the camera view zooms in until it fits snugly in the vertical space of the screen. As a result of this, if a screen is particularly tall and particularly narrow, a lot of the width of view gets cropped at the edges. (If you are making a landscape game, the same principles apply, just the view is really wide).
Both 2D and 3D elements should scale pretty gracefully between different screen sizes. A really high-res screen like on the iPad 3 will cause some graphics to look blurry, but if you design with the highest-res in mind, it should scale down pretty well.
The tricky part is if you want to position a GameObject in the corner of the screen, no matter what the screen size is. To accomplish this, you can use a Camera function:
 Vector3 worldPos = Camera.main.ViewportToWorldPoint(Vector3.zero);
 
               This would give you the world position of the lower-left corner of the screen; Vector3.one would be the top-right corner of the screen. By positioning things this way, you give your game a fluid layout (sort of like a webpage, but the user can never resize the window :P)
Thanks for this tip, however, I am having trouble at the initial placement of the camera. For example, let's say I have a room with a door in the center, and the camera is pointing at the door (you can view the whole room). If I choose "Free aspect" in the game window within Unity, everything is ok. But when I choose android 4:3 or 480x800 for example, I only see a small part of the scene, say just the door.
How do I fix that?
I think you'd have to do a bit of coding the camera's properties to get this effect. You could either change the Camera's Z position depending on the screen width, or you can adjust the field of view/camera size depending on the screen width.
For example, I think with a bit of trigonometry, you can calculate how far back the camera would need to be on a device-by-device basis. If you know the world positions of the farthest left and farthest right you'd need to view on the screen, you could then calculate how far back the camera would need to be based on the field of view.
 #---------#
  \       /
   \     /
    \   /
     \A/
      C
 
                  Where the # signs are furthest left/right, A is field of view, C is camera.
I'm not aware of an easier way.
That's exactly what I had in $$anonymous$$d: to change camera's Z position based on screen width.
Regarding the height of the screen, is it a good idea to play with the camera's size/field of view (not sure which one), in order to make it fit in the screen?
Camera size is used with orthographic cameras, whereas field of view applies to perspective cameras.
As for whether to use Z positioning or changing the field of view, I'd just experiment with changing the size of the game window and adjusting the camera settings. I could imagine that changing the field of view causes some sort of distortion, but I'm not sure.
Your answer
 
             Follow this Question
Related Questions
Particle System appears wildly different in editor, web player, android 1 Answer
OrthographicSize on Android changes from Start to Update? 0 Answers
Aspect Ratio problem 0 Answers
Can't run a game widescreen/Landscape , its portrait always. 1 Answer
Android - Normalize touch position based on mobile screen size 1 Answer