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 The_r0nin · Dec 10, 2010 at 02:02 AM · rotationjavascriptguiscreen

Finding the Screen Coordinates of the horizon when camera is rotating?

I have a GUI Line (GUITexture) that stretches across the screen attached to my player object. I also have the main camera parented to my player object. In its default position (with the camera facing forward) the GUI line divides the screen in half at Screen.height/2. There is a script attached to my player object that will rotate the camera up and down (positive and negative around the x-axis).

What I would like to have happen is that, when the player rotates the camera down (so that the center of the screen is now pointing in a downward angle), the GUI line stays on the horizon (at y=0 in the player's space, but not the camera's), meaning that the line would seem to rise up the screen until it is no longer visible (when the down angle gets large enough). How would I determine efficiently (especially since this is a GUI function and will be called multiple times a frame) where the original y=0 line is on screen to find out how high on the screen the GUI line needs to be drawn. Every idea I have come up with so far either requires an empty object to be created or rather dodgy mathematics. There must be a simpler way!

Thanks for any help!

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 The_r0nin · Dec 10, 2010 at 04:44 PM

I've figured it out. The code:

var linePos:float; // y value of line

var tempLinePos: Vector3 = mainCam.WorldToScreenPoint(mainCam.transform.position+Vector3.forward*mainCam.nearClipPlane); linePos = Screen.height - tempLinePos.y;

linePos is the y value on the screen to place my line at. I then take the World to Screen point of a spot on the near clipping plane (Vector3.forward*mainCam.nearClipPlane) that corresponds to right in front of the camera. I then need to subtract it from the screen height (since camera and mouse/GUI y coordinates are inverted). Now the GUI line seems to stay static while the camera is rotating up or down.

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

Js Object following rotation of another object 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Changing 3d text through script 1 Answer

Is it possible to link character skill lists to a GUI, and if so, how? 3 Answers

Move the text in a GUI Button/Box 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