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 BearShark1993 · Dec 29, 2013 at 08:37 PM · guiguitexturegui-windowgui-skin

Creating a FlightSim Like GUI HUD for Showing the player the angle of the Camera.

So I'm creating a game where the player is blind and has sonar like vision. What I'm trying to do is to create a GUI system that will indicate the angle the player is looking at to indicate the player if he's looking up or down while blind. At the moment I have a place holder which is simply a GUI label displaying the Euler Angle of the main camera. But what I want to do is to have a flight-sim like projected HUD like in the attached photo. Is there an example project anywhere? or anybody know how to I go about this. alt text

acombat44.jpg (33.6 kB)
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
2
Best Answer

Answer by robertbu · Dec 30, 2013 at 12:50 AM

I would be reluctant to use eulerAngles for rotating an indicator. There are multiple euler angles for any physical rotation, and Unity can change the representation as the object rotates. If you are just talking about the horizon lines, here is one simple solution:

  • Create a Quad that has a texture representing your horizon lines

  • Put the Quad just in front of the near clip plane of the camera. Assuming you are using a Perspective camera, that means you will need to scale the Quad way down to fit in the screen.

  • Make the Quad a child of the camera.

  • Add the following, simple script.


    pragma strict

    function LateUpdate() { transform.rotation = Quaternion.identity; transform.rotation = Quaternion.LookRotation(transform.parent.forward); }

Note you will get the best behavior if the Quad is anchored at the center of the camera. That means if you want the indicator to be above or below the center, you'll have to oversize the texture and move the indicator above/below the center of the texture.

Comment
Add comment · Show 9 · 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 robertbu · Dec 30, 2013 at 01:49 AM 0
Share

And here is a bit of code for the compass indicator:

  • Create a Quad just in front of the near clip plane

  • Attach an indicator arrow which points right

  • $$anonymous$$ake the Quad a child of the camera.

  • Attach the following script.


    pragma strict

    private var tr : Transform; private var pr : Transform;

    function Start() { tr = transform; pr = transform.parent; }

    function LateUpdate () { var v = pr.right; v.y = 0.0; if (v != Vector3.zero) { var angle = $$anonymous$$athf.Atan2(v.x, v.z) * $$anonymous$$athf.Rad2Deg; transform.localRotation = Quaternion.AngleAxis(angle, Vector3.forward); } }

avatar image BearShark1993 · Dec 30, 2013 at 03:33 AM 0
Share

I did what you said but what I need the pitch indicator to do is to animate as the camera rotates up or down Like in this video around the 1:20 http://www.youtube.com/watch?v=uPbSPU8F3Fo

avatar image robertbu · Dec 30, 2013 at 09:12 AM 0
Share

An indicator like the one in the video is not hard IF you can get accurate angles. You can probably use eulerAngles if you keep X and Z rotation less than 90 degrees, and you normalize them into -180 to 180. You can also keep accurate angles if you keep your own Vector3 representing the angles and assign that Vector3 to eulerAngles (and treat eulerAngles as write-only). So if you have the angles, the script is trivial, but the setup takes a number of steps:

  • Add a quad to the scene that will have your markings

  • Create a new layer and assign it to the quad

  • Add a second camera to the scene

  • $$anonymous$$ake the camera orthographic

  • Set the viewport for the new camera camera. For example, X:.3, Y:.3, W: .4, H:.5.

  • Set the culling mask so that it only see the new camera

  • Set Clear Flags to 'Depth Only'

  • Set depth to 1

  • On the main camera, remove the new layer from the culling mask.

  • Disable or remove the 'Audio Listener' from the new camera

  • Size and position the Quad as appropriate. Note the quad will be bigger than the viewport to allow the marking to scroll into view.

  • Attach the following script to the Quad with the markings

  • Link whatever script knows the angles to the script below and have it set 'angles' each frame.


    pragma strict

    public var angles : Vector3; public var angleToOffset = 0.01;

    function LateUpdate () { transform.rotation = Quaternion.AngleAxis(-angles.z, Vector3.forward); transform.position.y = angles.x * -angleToOffset; }

'angleToOffset' will have to be adjusted as appropriate to the spacing of the lines on the Quad texture.

avatar image BearShark1993 · Dec 30, 2013 at 07:04 PM 0
Share

I have a question about step 6 setting the culling mask on the new camera. How do I set it to only see the new camera do I uncheck everything?

avatar image robertbu · Dec 30, 2013 at 11:20 PM 0
Share

First you set the culling mask to 'Nothing', then you select the layer you want.


I ran a quick test of the steps above before I posted them. I put the following script on the camera:

 #pragma strict
 
 public var hud : HUD;
 public var speed = 20.0;
 private var angles : Vector3;
 
 function Start() {
     angles = transform.eulerAngles;
 }
 
 function Update() {
     angles.z += Input.GetAxis("Horizontal") * speed * Time.deltaTime;
     angles.x += Input.GetAxis("Vertical") * speed * Time.deltaTime;
     transform.eulerAngles = angles;
     hud.angles = angles;
 }

In initialized 'hud' by dragging and dropping in the Inspector. Note how 'angles' is manipulated and then assigned to 'transform.eulerAngles'. 'eulerAngles' is never read.

Show more comments

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

19 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

Related Questions

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

need help croping texture.... something wrong with my guigroup. 0 Answers

My GUITexture looks awful 2 Answers

Use the GUITexture to go to the next scene 1 Answer

Create a Start screen using guitexture over the main menu 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