Hi,
I have the following script to control my airplane in air. I ‘stole’ some values from the wikipedia page of the F-16 aircraft and I applied those to the model in game.
void FixedUpdate()
{
float L = 0.5f * Globals.AirDensity(transform.position.y, AltUnit.Meters) * rigidbody.velocity.magnitude * m_Planform * 2.0f * Mathf.PI * Vector3.Angle(transform.forward, Vector3.up);
float pitch = Input.GetAxis("pitch");
float roll = Input.GetAxis("roll");
float yaw = Input.GetAxis("yaw");
float finalRotFactor = m_RotSpeed * (Thrust / MaxThrust);
rigidbody.AddRelativeTorque(Vector3.right * pitch * finalRotFactor, ForceMode.Impulse);
rigidbody.AddRelativeTorque(Vector3.up * yaw * finalRotFactor, ForceMode.Impulse);
rigidbody.AddRelativeTorque(Vector3.forward * roll * finalRotFactor * 4, ForceMode.Impulse);
rigidbody.AddForce(transform.forward * Thrust * 2, ForceMode.Impulse);
rigidbody.AddForce(Vector3.up * L, ForceMode.Force);
m_Lift = L;
m_Velocity = rigidbody.velocity.magnitude;
}
Now it kinda works. I can fly around and all that, but the moment I turn or bank, it feels like I’m drifting through the air. It’s like it still applies the force towards the old angle that the aircraft was in.
How do I stablize it to go forward and not slip ‘n’ slide all over the place? And… is this script correct? Am I doing something wrong? Thanks!