how create modern aircraft's hud

25852-ace-combat-5-the-unsung-war-20041025071013334.jpg

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…?

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.

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