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
7
Question by stromdotcom · Oct 06, 2011 at 07:35 PM · mathunitsdimensions

What is the relationship between camera size, units, mesh size and resolution?

When I'm working with an orthographic camera (doing 2D) I keep running into this issue where it would be great to know the math behind the relationship of the camera size and the units in unity space.

For example, if I know I'm in 1024x768 resolution, and my camera size is 1, and I want a mesh that completely fills up the screen exactly, how do I calculate it's dimensions?

And if I switch to 960x640 resolution, how do I know how to adjust the camera and resize the mesh to fit the new resolution exactly? What if the camera is now size 1.2? etc.

I know there has to be some math that should be nailed to my wall that I can use to do these calculations.

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

3 Replies

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

Answer by aldonaletto · Oct 06, 2011 at 10:58 PM

The height is 2 * size, and the width is height * aspect. You can calculate them with these instructions:

  var height = 2*Camera.main.orthographicSize;
  var width = height*Camera.main.aspect;
Comment
Add comment · Show 5 · 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
avatar image stromdotcom · Oct 06, 2011 at 11:27 PM 0
Share

Ok, this makes sense. And then everything just scales to the resolution I assume? So if I have resolution set to 1024x768, then I can assume that 2m in unity units = 768 pixels in pixel space? If so, will it always scale by height?

avatar image aldonaletto · Oct 07, 2011 at 12:22 AM 1
Share

Yes, height is the "official" screen measure in Unity - height is directly related to the Size (or orthogonalSize), and width is related to height. Depending on what you need to do, maybe it's a better idea to use Camera.main.ScreenToWorldPoint to convert pixel to world coordinates. This function receives a parameter Vector3 where x and y are the pixel coordinates and z is the distance from the camera, and returns the corresponding point in the 3D world. The inverse function also exists, WorldToScreenPoint: it converts a 3D world point to pixel coordinates x and y (the z value returned is the distance from the camera)

avatar image siddharth3322 · Jan 16, 2014 at 12:21 PM 0
Share

Thanks for your simple explanation.

avatar image gameCoder95 · Jun 03, 2017 at 07:14 PM 0
Share

Thank you aldonaletto! You saved me from a lot of frustrating headaches!

avatar image Bovine · Jan 27, 2021 at 02:15 PM 0
Share

Thanks. Hopefully this translates to render to texture so I can calculate pixel from world space :)

avatar image
3

Answer by Tseng · Oct 06, 2011 at 10:46 PM

The Orthographic size is the visible area from center of the screen (read: half height) to the top in unity units (1 unity unit = 1m).

So if you have a orthographic size of "1" it will show exactly 2 units height (2 meters). So if you have a standard cube (Menu GameObject > Create Other > Cube), then it will be exactly half the screen height, because the default is 1x1x1 units.

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
avatar image
2

Answer by carlos.castaneda · Jan 21, 2013 at 04:42 AM

The solution isn't scale every object in your scene, in fact is "re-size" the projection of the camera according to a specific aspect-ratio, take a look this: for me is THE SOLUTION !!!

http://gamedesigntheory.blogspot.com/2010/09/controlling-aspect-ratio-in-unity.html

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

11 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

Related Questions

Measuring distance on Camera Screen-Space Canvas in -canvas units- 1 Answer

Make a value inverted/opposite. 0 Answers

Problem with mathf function 2 Answers

Bomb Trajectory for a "Water Canon" (Maths) 1 Answer

health bar position formula 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