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 Lord Simpson · May 11, 2011 at 04:58 PM · guiquaternionhudoffscreen

Off Screen direction indicator HUD element / wrestling with Quaternion

Hi I'm attempting to create a HUD element that appears if the players target has left the screen,its fixed to the edges of the screen and helps inform the player which way to turn to get them in the view again. my game has full 3d movement so it has to work with all possible rotations. I've almost got it working I'm just having trouble with constructing the quaternion that allows me easy access to the values I need.

My current quaternion doesn't seam to take the roll into account correctly as so doesn't output the correct vector

Vector2 Offscreenindicator(Transform me,Transform target)
{
    //Construct a Quaternion that has x and y euler angles relative to the players roll
    Quaternion test = Quaternion.LookRotation(target.position-me.position,-me.up)*me.rotation;
    //make those euler angles easily accessable
    Vector3 temp = test.eulerAngles;
    float pitch = temp.x;
    float yaw = temp.y;
    //calculate the horizontal FOV
    float Hfov = (2* Mathf.Atan(Mathf.Tan((pc.cam.fieldOfView * Mathf.Deg2Rad)/2)*pc.cam.aspect))*Mathf.Rad2Deg;
    //normalise the angles to a 180 to -180 system
    if(pitch > 180)
        pitch -= 360;
    if(yaw > 180)
        yaw -= 360;
    //clamp the angles to the edges of the screen then normalise them to 0 to there feild of view
    pitch = Mathf.Clamp(pitch,-pc.cam.fieldOfView/2,pc.cam.fieldOfView/2)+pc.cam.fieldOfView/2;
    yaw = Mathf.Clamp(yaw,-Hfov/2,Hfov/2)+Hfov/2;
    //compare with the feild of view to convert to a screen locaton
    pitch = (pitch / pc.cam.fieldOfView)*(Screen.height);
    yaw = (yaw/Hfov)*Screen.width;
    //return a value that can be used with GUI Components
    return new Vector2(yaw,pitch);
}

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 Lord Simpson · Aug 08, 2011 at 10:59 PM

In the end replaced the whole idea with a pointer instead that is only a few cm [0.1] units big and floats a meter or so in front of the camera pointing to the target and moving towards it by a small degree. Also I deactivate the mesh render if the Vector3 angle between its pointing direction and the cameras forward vector are below 30 so it doesn't take up screen space when the target is obviously visible. If the target is directly behind you the pointer looks larger as its closer to the screen and points directly towards the camera.

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

1 Person is following this question.

avatar image

Related Questions

How to position 3D-GUI-Mesh on change of aspect ratio? 0 Answers

Maintaining Image Aspect Ratios in GUI using Matrix? 1 Answer

layer 2 guis onto of another 2 Answers

Make my HUD full screen 2 Answers

Multi Camera HUD buttons not working. 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