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
2
Question by user-10304 (yahoo) · Mar 15, 2011 at 01:35 PM · cameraresolutionscreenorthographic

Orthographic cameras and screen resolutions

Hi,

This was originally posted as a question on the forums, but sank without a trace and with no responses, and I thought it might be better suited to unityanswers instead.

I've had a good trawl through various forum posts and other questions on this, which has partly helped me to get to the point I am at now. I am trying to create a simple window using an orthographic camera where the bottom left corner has coordinates of (0, 0, 0) no matter what the actual window size/screen resolution. So far I have produced the following script:

function Start() { resolutionCounter=0;

Screen.SetResolution(Screen.resolutions[0].width, Screen.resolutions[0].height, false);

Camera.mainCamera.orthographicSize = Screen.height/2; Camera.mainCamera.transform.position = new Vector3(Screen.width/2,Screen.height/2,-100);

referenceObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); referenceObject.transform.position = new Vector3(10,10,10); referenceObject.transform.localScale = new Vector3(10, 10, 10); }

function Update () {

 if (Input.anyKeyDown)
 {

      if (resolutionCounter<Screen.resolutions.Length-1)
      {
         resolutionCounter++;
      }
      else
      {
           resolutionCounter=0;
      }

      Screen.SetResolution(Screen.resolutions[resolutionCounter].width, Screen.resolutions[resolutionCounter].height, false);
      Camera.mainCamera.orthographicSize = Screen.height/2;
      Camera.mainCamera.transform.position = new Vector3(Screen.width/2,Screen.height/2,0);
  }

}

This code allows me to cycle through the supported resolutions properly. However, it doesn't keep the created sphere 10 pixels from the bottom and left of the window, which I thought should be the case no matter what resolution is chosen. In fact, the sphere jumps all over the place, and is sometimes not in the window at all.

Am I doing something wrong here, or is my understanding of what should be happening incorrect?

Thanks,

Wibbs

Comment
Add comment · Show 4
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 AngryOldMan · Mar 15, 2011 at 01:50 PM 0
Share

not had a chance to try your script but I'm pretty sure you don't want the lines in which you transform/move the camera. Try commenting them out and see what happens, also switch between your Scene and Game tabs to see what's going on.

avatar image user-10304 (yahoo) · Mar 15, 2011 at 03:45 PM 0
Share

I'm not at my computer at the moment so can't check this, but isn't it the move/transform that ensures the camera is centred in the 'active' area?

avatar image Wibbs 1 · Mar 15, 2011 at 05:51 PM 0
Share

Unfortunately that does not seem to solve the problem, so I'm still stumped :(

avatar image Wibbs 1 · Mar 15, 2011 at 06:35 PM 0
Share

O$$anonymous$$, I can refine the question a little now. What I am trying to do is get a 1 to 1 mapping between world space and camera space. I've added test code to print out points in both, and it clearly isn't working, but I don't know why. Any ideas?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Wibbs 1 · Mar 15, 2011 at 06:57 PM

Okay,

I've found the answer to this. Screen.width and Screen.height seem to lag behind and were not being updated in time for changing the camera's orthographic size or position in the same Update call. I replaced these lines with:

Camera.mainCamera.orthographicSize = Screen.resolutions[resolutionCounter].height/2;
Camera.mainCamera.transform.position = new Vector3(Screen.resolutions[resolutionCounter].width/2,Screen.resolutions[resolutionCounter].height/2,-100);

and now everything works as expected, with world space giving the same x,y coordinates as camera space.

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

No one has followed this question yet.

Related Questions

2D Game. Screen, Camera and coordinates. 0 Answers

4:3 aspect ratio 0 Answers

Orthographic camera cuts off half of screen in Web Player - resolution error? 1 Answer

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

Make camera have a fixed screen size 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