space flight mechanics.

I have a script that allows you to fly in a zero g environment. how ever when you bump into something you go into a roll that doesnt stop, nomatter how much you turn the other way and try to level yourself out. is there away to keep this but only for a small amount of time. so instead of wildly flying off into space you just bounce off and wildly roll for a little bit and then level out so you can begin playing again?

You could probably achieve this by increasing the "Angular Drag" value on your object's Rigidbody component.

Angular drag dampens the angular momentum (the rotation) of the object only.

If you actually want the object to self-right, that's a little trickier. Here's some code which self-rights an object, but you might want to combine it with angular drag, and modify it so that it only kicks in once the angular velocity has dropped below some threshold level - so that it self rights once the spinning has slowed to a certain speed.

using UnityEngine;
using System.Collections;

public class SelfRight : MonoBehaviour {

    public float selfRightSpeed = 0.1f;

    void FixedUpdate () {
            Vector3 flatFwd = new Vector3(transform.forward.x, 0, transform.forward.z);
            Quaternion fwdRotation = Quaternion.LookRotation(flatFwd, Vector3.up);
            transform.rotation = Quaternion.Slerp(transform.rotation, fwdRotation, Time.fixedDeltaTime * selfRightSpeed );     
    }
}

Note - it would probably be more correct to self-right the object by applying torque to the rigidbody, rather than adjusting the rotation directly, but I can't figure that out in my head right now... need to sleep! Maybe I can edit this another time if required.

I have some self-righting code in my game here: http://www.tosos.com/ShooterMark2.html so you can see how it works (just start single player wasd to move and mouse to shoot. Blow up one of the asteroids).

Here's the code:

var restore : Vector3;

function FixedUpdate () {
    if (rigidbody.position.y != 0) {
        rigidbody.AddForce (0, rigidbody.position.y * -restore.y, 0);
    }
    zoff = transform.localRotation * Vector3(1, 0, 0);
    xoff = transform.localRotation * Vector3(0, 0, 1);
    rigidbody.AddRelativeTorque(-xoff.y * restore.x, 0, zoff.y * restore.z);
}

That "AddForce" is what keeps the ship and asteroids on the 2d y=0 plane. Basically it works like a spring measuring how far the normal vectors are off from normal and then has the spring pull it back in.

Depending on when you look at this the effect might be less pronounced. I do this by increasing the angular drag and also increasing the "restore" values. At the more damped level it's restore = (500, ?, 1000) and drag = 5 (at the lower level I think it was drag = .2 and restore = (75, ?, 75)