• 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 appllee · Apr 28, 2014 at 06:00 AM · guihudairplane

how create modern aircraft's hud

alt text

t$$anonymous$$s is what i want to create. there's horizontal lines for each 5 degrees. if the camera is rotated, horizontal line will also rotate same as that picture.

first i thought 1. make full texture 2. rotate the texture when trasform rotates. but i t$$anonymous$$nk t$$anonymous$$s way is wasting.

i want to create the line with gui line(like 'Vectrosity').

how can i draw a line matc$$anonymous$$ng to horizon..?

ace-combat-5-the-unsung-war-20041025071013334.jpg (20.0 kB)
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 Rioneer · Apr 28, 2014 at 06:41 AM 0
Share

Draw the static texture first then draw gauges. Rotate or move your gauges using transform variables. What's wrong with using a texture as your line? Edit : You may also want to use sprites, they are easier to handle.

avatar image appllee · Apr 28, 2014 at 01:41 PM 0
Share

thanks, sprites will also fine. but i still have problem with matching degree lines to world.. i have no idea about that

avatar image Rioneer · Apr 28, 2014 at 06:12 PM 0
Share

Parent the line's y rotation to your plane?

avatar image appllee · Apr 30, 2014 at 05:17 AM 0
Share

i cant explain what i need(im noob).. but Robertbu's answer is exactly what i want

2 Replies

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

Answer by robertbu · Apr 29, 2014 at 12:44 AM

but i still have problem with matc$$anonymous$$ng degree lines to world.

No matter how you draw your HUD, you have the same underlying problems. That is you are going to have to rotate and/or offset some form of grap$$anonymous$$cs based on the rotation of the plane. In respect to rotation, you have three primary pieces of information you need: heading, pitch and roll. If you are rotating the plane by directly manipulating the eulerAngles, you can use your own Vectror3, but I'm guessing you will be using a Rigbody.

Here is a bit of example code I w$$anonymous$$pped up to get the heading, pitch, and roll. Put it on your plane and see the values output in the upper left of the screen. It's only lightly tested, and there may be better ways:

 #pragma strict
 
 private var heading : float;
 private var pitch : float;
 private var roll : float;
 
 function Update () {
     // Heading
     heading = Mathf.Atan2(transform.forward.z, transform.forward.x) * Mathf.Rad2Deg;
     
     //pitch
     var pos = ProjectPointOnPlane(Vector3.up, Vector3.zero, transform.forward);
     pitch = SignedAngle(transform.forward, pos, transform.right);
     
     // roll
     pos = ProjectPointOnPlane(Vector3.up, Vector3.zero, transform.right);
     roll = SignedAngle(transform.right, pos, transform.forward);
 }
 
 function OnGUI() {
     GUI.Label(Rect(20,0,100,40), heading.ToString());
     GUI.Label(Rect(20,50,100,40), pitch.ToString());
     GUI.Label(Rect(20,100,100,40), roll.ToString());
 }
 
 function ProjectPointOnPlane(planeNormal : Vector3 , planePoint : Vector3 , point : Vector3 ) : Vector3 {
     planeNormal.Normalize();
     var distance = -Vector3.Dot(planeNormal.normalized, (point - planePoint));
     return point + planeNormal * distance;
 }    
 
 function  SignedAngle(v1 : Vector3,v2 : Vector3, normal : Vector3) : float {
     var perp = Vector3.Cross(normal, v1);
     var angle = Vector3.Angle(v1, v2);
     angle *= Mathf.Sign(Vector3.Dot(perp, v2));
     return angle;
 }


Heading - because of the way the math works out, when transform.forward is facing Vector3.right, the angle will be 0.0. Assuming you want Vector3.forward to be north, you would construct your indicator to point to the right when the rotation is (0,0,0).

Roll - You can just use the value directly in a AngleAxis(roll, Vector3.forward) rotation. You may have to negate roll in the call.

Pitch - You will be moving the indicator up and down with respect to the value. You need to multiple the pitch by some factor for the offset. You can figure out the factor by trial and error.

Comment
Add comment · Show 2 · 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 appllee · Apr 30, 2014 at 05:18 AM 0
Share

Thanks for answering my noob question. ill try it later

avatar image SonicScrew12 · Mar 12, 2016 at 03:10 AM 0
Share

Hate to resurrect an old post but I have a problem when using this script with my own PFD (Primary Flight Display). I'm using 2 sprites, one for the background, and one for the line that shows your relative rotations. When I apply this script to my sprite, it rotates it in such a way that, due to your SignedAngle() function, it teleports the line showing rotation all the way downward when I turn upside-down using pitch, and same with roll.

 function FixedUpdate () {
       targ.transform.rotation = Quaternion.AngleAxis(roll, Vector3.back);
       targ.transform.position = Vector3(targ.transform.position.x, pitch * 1.5 + 128, targ.transform.position.z);
 }

This is the code I am using. I am simply using "targ" (a GameObject) to change its position and rotation based on the above code. The multiplication and addition is to keep my "targ" to start in the right spot. However, I think since this exists:

  function  SignedAngle(v1 : Vector3,v2 : Vector3, normal : Vector3) : float {
      var perp = Vector3.Cross(normal, v1);
      var angle = Vector3.Angle(v1, v2);
      angle *= Mathf.Sign(Vector3.Dot(perp, v2));
      return angle;
  }

I believe this is what is causing my teleportation, as it always wants me to have positive values. Of course, I may be wrong, but something in this code is making it so that my "targ" cannot rotate freely.

Edit: Forgot to add what I think might help...

alt text

example.png (321.7 kB)
avatar image
0

Answer by Maloke · Jun 24, 2021 at 04:19 PM

Just in case someone is still looking for an aircraft HUD, you can find one ready to use here.

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 agulsahe · Aug 22, 2022 at 10:03 AM 0
Share

thank you. Is this your Hud Project?

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

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

Related Questions

Runescape style window? 1 Answer

Multi Camera HUD buttons not working. 1 Answer

Best way to create mini hp-bars for enemies. 1 Answer

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

GUI Question please help. 2 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