• 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
1
Question by moghes · Apr 26, 2013 at 05:27 AM · 2dpositioningorthographicscreen.width

Position 3d objects in 2d space (orthographic cam)

Hello,

I am using sprites and an orthographic camera, I have a sprite as a background and other sprites as animated object. I need to position the objects in the 2d space. To be more clear, consider a box (GUI.Drawtexture) at center, you could have Rect(Screen.width/4 , Screen.height/2 , Screen.width/2 , Screen.height/3); you can do anything with Screen.width and Screen.height.. I need to know what to do with the sprites. I tried a method:

 height = Camera.mainCamera.orthographicSize*2;
 width = (Screen.width / Screen.height) * height;

I am printing the values on the screen and I got 0 for width ,2 for height on the ipad, and 4 for width and 2 for height when ran on editor.. I can't figure out what these numbers means.. Is there an another method?

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
4
Best Answer

Answer by robertbu · Apr 26, 2013 at 01:24 PM

There are four coordinates systems used by Unity: GUI, Viewport, Screen, and World. There are ways to convert between them. The GUI.DrawTexture() uses GUI coordinates. The width/height are distances in world space, but don't represent coordinates at all. How to solve your problem will depend on what you are trying to do. To make the kinds of positioning you describe with GUI.DrawTexture using an object that lives in world space, you can use Viewport coordinates and convert them to world coordinates using Camera.ViewportToWorldPoint(). Viewport coordinates start at (0,0) in the bottom left and go to (1,1) in the upper right. So to positions something 1/4 up from the bottom and 3/4 the way across the screen:

 var v3Pos = Vector3(0.25, .75, 10);
 v3Pos = Camera.main.ViewportToWorldPoint(v3Pos);

Note that the 'Z' parameter of the Vector3 is the distance in front of the camera which is more of a concern for a perspective camera than an orthographic camera.

Comment
Add comment · Show 1 · 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 moghes · Apr 29, 2013 at 06:37 AM 0
Share

Thank you!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Why is this pixel art not lining up correctly? 1 Answer

2D Animation does not start 1 Answer

2D Space Shooter Instantiating bullet question 1 Answer

How to know that image is attached with either its left or right side 0 Answers

Background Image as Orthographic 2D Game Background - and quick 2D parallaxing question 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