Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by cacotigon · Jun 12, 2015 at 04:41 PM · cameraresolutionorthographic

How to set constant orthographic viewport?

I've been experimenting with 2D game project in Unity and started a very simple pong game to get acquainted with unity but I'm having a difficult time grasping the concept of the orthographic camera.

When I click on the orthographic camera, it has values of [0, 0, -10] for the XYZ values. I've been reading up on the orthographic size and how the camera viewport height seems to correspond to 2 * Camera.OrthographicSize. I've set the size to 40 and I've put top and bottom wall sprites at -40 and +40. So far so good.

I've also read how the Viewport width corresponds to Viewport Height * Aspect Ratio, except that I have no idea what the default aspect ratio for the game is at this point. This is problem #1.

From eyeballing the camera viewport width, it seems to be at about -60 and +60, indicating an aspect ratio of 3:2. Okay I guess....

sigh, I just want to be able to set my camera viewport at a certain size, say 320x240, use my sprite set of consisting of 16x16 sprites, and visually design the UI by dragging in the sprites to the appropriate places on the Scene; ideally I'd be able to set a Snap Grid (like Photoshop) and lay everything where it is supposed to be.

Then when people play the game, they can pick from a set of resolutions (320x240, 640x480, 800x600, etc) but the game just upscales the output from the original 320x240 resolution, so that internally (in code and scene designer) I only have to deal with a single defined resolution.

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

Answer by NoseKills · Jun 12, 2015 at 08:37 PM

There's quite a lot of similar questions on UA, and the first problem is that people don't usually realize this is a design question first and a programming problem only after that.

You simply can't make a game "look the same" on two devices that have different aspect ratios. So unless you have total control over the resolution of the target device (only desktop version & only windowed mode, or a very strictly limited set of mobile devices), you'll have to compromise either by

  1. having black bars on the sides or top and bottom of screen

  2. resizing camera to crop the content by height or width

  3. scaling only x or only y of the content to fit the screen perfectly, but losing the proportions of your game world in the process

You don't specifically mention if or how you have solved the design problem. If you do have total control of the resolution so that the aspect never changes, the orthographic camera already does all the work for you. If you don't, you can

  1. Investigate the black bars solution

  2. Change the camera size with the same principle as above (I believe multiplying/dividing your original orthographicSize with float scaleheight will crop the image by height or width depending which you want

  3. why would anyone want to do this...

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why Is My Orthographic Camera Not Rendering at the Full Resolution? 1 Answer

2D Aspect Ratio Of Camera 2 Answers

Same camera view on different resolutions 0 Answers

Keep Aspect ratio/Letterbox and maintain pixel perfection 0 Answers

Orthographic Camera Size? 3 Answers


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