Here's how you can turn a rigidbody using quaternions.
Give it a vector where each component represents the amount you want to rotate on that axis, local to the object. So if you wanted to pitch upward slightly while rolling sharply, you would pass "new Vector3(0.0,0.25,1.0)"
var yaw = 45.0;
var pitch = 45.0;
var roll = 60.0;
function Turn(direction) {
var xrot = pitch * direction.x * Time.fixedDeltaTime;
var yrot = yaw * direction.y * Time.fixedDeltaTime;
var zrot = roll * direction.z * Time.fixedDeltaTime;
var xQuaternion = Quaternion.AngleAxis (xrot, Vector3.right);
var yQuaternion = Quaternion.AngleAxis (yrot, Vector3.up);
var zQuaternion = Quaternion.AngleAxis (zrot, Vector3.forward);
var totalRotation = xQuaternion * yQuaternion * zQuaternion;
rigidbody.MoveRotation(rigidbody.rotation * totalRotation);
// comment the above line and uncomment the below to turn a transform
//transform.rotation *= totalRotation;
}
You can also slowly turn an object to any given point in 3D space with this:
function turnTo(direction : Vector3) {
var destination_rot = Quaternion.LookRotation(direction);
var str = Mathf.Min (yaw * Time.fixedDeltaTime, 1);
rigidbody.MoveRotation(Quaternion.Slerp(rigidbody.rotation, destination_rot, str));
// comment the above line and uncomment the below to turn a transform
//transform.rotation = Quaternion.Slerp(transform.rotation, destination_rot, str);
}
Of course, this assumes that you want it to determine its turning speed purely through the yaw value, and you want it to take the shortest path there even though it might not look the best for the given object (like you'd probably want an airplane to bank). For some reason I have to turn the yaw value down to about 1.0 for the second function, I think I need to add a bit that will compute str in terms of yaw's value and then clamp that to a 0.0-1.0 range.