# plane banking torque

I am using this script for my space-plane thing.

``````var Throttle = 60;
var Brake =  -60;

function FixedUpdate () {
if (Input.GetKey(KeyCode.Mouse0)) {    // space is pressed - apply force here}
rigidbody.AddRelativeForce(0,Throttle,0);
print("Throttle");

}
if (Input.GetKey (KeyCode.Mouse1)) {
rigidbody.AddRelativeForce(0,Brake,0);
print("Brake");
}
if (Input.GetKey (KeyCode.A)) {
rigidbody.AddTorque(0,0,0.01 * Throttle);
rigidbody.AddRelativeForce(0,0,0.4);

}
if (Input.GetKey (KeyCode.D)) {
rigidbody.AddTorque(0,0,-0.01 * Throttle);

}
if (Input.GetKey (KeyCode.W)) {
rigidbody.AddRelativeTorque(Vector3.right * 2);
}
if (Input.GetKey (KeyCode.S)) {
rigidbody.AddRelativeTorque(-Vector3.right * 2);
}
}

``````

It works well until it starts to turn, in which the plane cannot level out, and the left and right will start doing the opposites of what they should. Why?

Try this:

``````function FixedUpdate () {
rigidbody.AddRelativeTorque (Input.GetAxis("Vertical"),0, -Input.GetAxis("Horizontal"));
}

``````

That deals with the rolling and pitching, add a key for the middle variable for yaw. You also need to add an up force relative to speed (unless it's a space game). To stop spinning after releasing the keys you can use a high angular drag on the rigid body or do it with a script adding opposite torque when you release the keys. For auto leveing (not much sense in space) you need to find the current rotation and add force towards 0 rotation.

Ask again if you need more specifics.