Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by inejwstine · Sep 25, 2018 at 09:14 PM · 2daspect-ratioaspect ratioaspectratio

How to maintain width at lower aspect ratios?

In a 2D game, when switching from a higher aspect ratio to a lower one (for example, from 16:9 to 4:3), the width of the viewing window shrinks, causing elements near the sides to get "cut off." Is there an easy way (perhaps a setting, script, or component) to add height instead of subtracting width when changing to a lower aspect ratio? In other words, instead of things near the sides getting hidden, more things near the top and bottom would be revealed.

I'm guessing this would involve zooming the camera out just enough so that whatever was at the left and right edge at the larger aspect ratio would still be at the edges at the lower one. Does anyone know if this has been done before? For the particular game I'm making, zooming the camera out to reveal more of the scene would be preferable to cutting off the edges. But if possible, I only want to zoom out if necessary.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by inejwstine · Sep 26, 2018 at 05:36 PM

I think I just found a workable solution for me. I'm sharing it in case it's helpful to anyone else. I wrote this very simple script and attached it to my Main Camera:

 public class AdjustToAspectRatio : MonoBehaviour {
 
     [SerializeField] private float _16By9CameraSize;
     [SerializeField] private float _4By3CameraSize;
 
     private const float RATIO_16_9 = 16f / 9f;
     private const float RATIO_4_3 = 4f / 3f;
 
     private float _aspectRatio;
     private Camera _camera;
 
     // Use this for initialization
     void Start () {
         _camera = GetComponent<Camera>();
         _aspectRatio = (float)Screen.width / Screen.height;
         var t = (_aspectRatio - RATIO_4_3) / (RATIO_16_9 - RATIO_4_3);
         var size = Mathf.Lerp(_4By3CameraSize, _16By9CameraSize, t);
         _camera.orthographicSize = size;
     }
 }

I'm expecting the aspect ratio of the devices that will be playing my game to be somewhere between 16:9 and 4:3. So I checked both ratios in the editor Game view and adjusted the camera's orthographic size (just "Size" in the inspector) at each ratio so it looked how I wanted and then entered those values into the corresponding fields.

Now when I play at 16:9, it sets the camera size to _16By9CameraSize. When I play at 4:3, it sets it to _4By3CameraSize. And when I play at an aspect ratio that's somewhere between the two (say, 3:2), this script will interpolate between the two values.

There may be a more elegant solution, but for now, this suits my needs. Feel free to use it or improve upon it. (If you do improve it, I'd love to hear how!)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

244 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I scale a scrollview item so it keeps its ratio? 0 Answers

Designed UI for 2:1 aspect raito, how do I also make it fit 16:9? 1 Answer

Resizable Window with Fixed Aspect Ratio? 2 Answers

Unity built game resolution issue 1 Answer

Camera and UI settings for aspect ratio independent 2D game 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges