Finding A Rigidbody's Rotation Speed And Direction

Hi, quick question:

speed = Vector3 .Dot (rigidbody.velocity , transform.forward )*50 ;

I have this for finding the velocity of my rigidbody, how could I do something similar to find out how fast and to which direction the body is rotating?

Many thanks :slight_smile:
Magnus

Just like you have rigidbody.velocity, you also have rigidbody.angularVelocity which gives you the “rotation velocity” (known in physics as angular velocity).

Read about it here:

Well to start it is simply to finds it speed in ‘velocity’. you Don’t need a Vector3 to is making stuff more complicated than needed.
speed= rigidbody.velocity.magnitude;
//This is more than enough, with magnitude it will spit out a
//single float value and will be the same as your Vector3 //version
and now to find your rotation speed you could use (note this is part of my own script
and only enables to one axis at a time).

The >=0 means it is moving in the positive site of its rotation the <=0 means it rotates in the negative direction. You can place Debug.Log to check it. If you need all directions checked you need to do some more complex stuff or you can simply duplicate that code 3 times, one for each direction and simply adjust the x,y,z;

private var lastRot:Quaternion;


function Update(){

//check if object is rotating
if(transform.rotation.y != lastRot.y && transform.rotation.y-lastRot.y >=0){  
your function here;
}


if(transform.rotation.y != lastRot.y && transform.rotation.y-lastRot.y <=0){  
your function here;
}


lastRot = transform.rotation;


}