- Home /
how create modern aircraft's hud
this 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 think this way is wasting.
i want to create the line with gui line(like 'Vectrosity').
how can i draw a line matching to horizon..?
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.
thanks, sprites will also fine. but i still have problem with matching degree lines to world.. i have no idea about that
i cant explain what i need(im noob).. but Robertbu's answer is exactly what i want
Answer by robertbu · Apr 29, 2014 at 12:44 AM
but i still have problem with matching 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 graphics 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 whipped 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.
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 *= $$anonymous$$athf.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...
Your answer
Follow this Question
Related Questions
Best way to create mini hp-bars for enemies. 1 Answer
How to position 3D-GUI-Mesh on change of aspect ratio? 0 Answers
Runescape style window? 1 Answer
Multi Camera HUD buttons not working. 1 Answer
GUI Question please help. 2 Answers