How to halt rotation after object collision?

I have some gameobjects floating around on the screen and they collide and bounce off each other they start rotating. This is something Unity does once you put a collider on something (no duh say the learned ones out there :slight_smile: ).

But on a certain event I want to stop the rotation of the gameobject that was started (by Unity) after the gameobject collision.

When the event occurs, in my code I do a:
transform.localRotation = Quaternion.identity;

This stops the objects rotation but also snaps the object back to its original default rotation (as it should).

But what I want is to only halt the rotation of the gameobject and but keep it at the rotation it was at.

What should I be setting to stop only the rotation motion?

Thanks for any help!

Is your object a rigidbody? If it is then i think the Freeze Rotation variable in the rigidbody component might be what you’re looking for.

Your code doesn’t stop the animation, it just overwrites the rotation with the default rotation.

Have you tried:

animation.Stop();

This should stop the current animation, usually the object keeps the last parameters as long as there’s not another animation that changes the rotation.

You can do this. I think, this solves your problem:

var cube : GameObject;
var a : int = 0;
function Update(){
   if(a == 0){
      cube.transform.Rotate(Vector3.up, 100.0f * Time.deltaTime, Space.World);
   }
}

function OnCollisionEnter(collision : Collision){
   a = 1;
}

It is a rigid body and setting freezeRotation=true at the time of my event did the trick.
Thank you!