Airplane goes weird on collision (Rigidbody)

Hey,

ok I have created a airplane with a rigidbody and attached a script to it. The airplane flies nicely but when it collides with something like the terrain then the rotation goes mad and it cannot easily return to normal.

Here is the code :

        var rotateSpeed = 3;
    var speed = 200;

    function Update () {

    transform.Rotate(Input.GetAxis("Vertical")
* rotateSpeed, 0, Input.GetAxis ("Horizontal") * rotateSpeed * -1);
        if (Input.GetButton("Jump")){
            rigidbody.AddForce (transform.forward * speed);
        }

    }

I rewrote parts of the script because the formatting as you pasted it was unfortunately hard to read for me.

var rotateSpeed = 3;
var speed = 200;

function FixedUpdate ( ) 
{
    var vertical = Input.GetAxis ( "Vertical" ) * rotateSpeed;
    var horizontal = Input.GetAxis ( "Horizontal" ) * rotateSpeed;
    var throttle = Input.GetButton ( "Jump" );
    var dt = Time.fixedDeltaTime;

    rigidbody.AddRelativeTorque ( Vector3.right * vertical * dt );
    rigidbody.AddRelativeTorque ( Vector3.forward * -horizontal * dt );

    if ( throttle )
    {
        rigidbody.AddForce ( transform.forward * speed * dt );
    }
}

I also moved physics code to FixedUpdate and include time variance. I also changed the rotation code to use Torque to make this an all-physics based simulation. I had a go around with the aircraft and it was pretty fun. I noticed that when colliding with something while flying fast you still tumble around a bit. I increased the rigid bodys angular drag coefficient and the simulation became quite nice.

So try this script, and tweak the aircrafts angular drag. Try increasing it a bit and see if you get more stable.