Flight Sim Controls

Hey everyone, I’m just getting started in Unity and having a blast.

Right now I’m trying to get some basic aircraft controls working and was wondering if someone could point me in the right direction. Even non-Unity example code would be awesome. I have had success creating a very arcade-like control scheme, but you cannot do rolls or loops. My issue is that my angles start getting all messed up when I enable that type of control.

Here is a snippet… I’m sure there is an easier way and I’m just not seeing it. This is for the iPhone BTW.

Limited controls (works perfectly, but not very aircraft-like

euler.y += accelerator.x * turnSpeed;
	
euler.z = Mathf.Lerp(euler.z, -accelerator.x * maxTurnLean, 0.2);

euler.x = Mathf.Lerp(euler.x, accelerator.y * maxTilt, 0.2 );

var rot : Quaternion = Quaternion.Euler(euler);
transform.rotation = Quaternion.Lerp(transform.rotation, rot, sensitivity);

My attempt at enabling loops was to make the x-axis rotation additive by changing the line above to this:

euler.x += accelerator.y * turnSpeed;

This works to some extent, but after you do a loop, all the controls are reversed. I tried the same with rolls (z-axis) and it was utter chaos.

Any help is much appreciated.

Probably something like

var moveSpeed : float = 50;
var yawSpeed : float = 90;
var pitchSpeed : float = 70;

function Update () {
	transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
	transform.Rotate (-Vector3.forward * Input.GetAxis("Horizontal") * yawSpeed * Time.deltaTime);
	transform.Rotate (Vector3.right * Input.GetAxis("Vertical") * pitchSpeed * Time.deltaTime);
}

–Eric

Thanks for the fast response. So is it best to just use this Rotate function than to mess with the Quaternion class? I’ll certainly try this out. I’ll let you know how it goes.

Works like a charm! Clearly, you are the man.