I’m trying to rotate an object 90 degrees forward to its rotation axis (-1, 0, 0). I’m using the cross product to calculate the rotation axis based on the movement direction and the current Vector3.up. Then I’m calculating the new forward and up direction and then I’m using these to get the new rotation for my object with Quaternion.LookRotation. The problem however is that the new rotation result is not 100% accurate, the result is: (89.98, 0, 0) while it should have been: (90, 0, 0). Any Ideas why? My code looks a bit like this:

Just a note, I’m not trying to Slerp to the new rotation - the variable newRotation result is (89.98, 0, 0) instead of (90, 0, 0), is that a normal thing when using Quaternions?

First of all, that’s not the value of newRotation. That’s the value of the eulerAngles conversion of the quaternion value. Also this particular rotation you’re talking about is one of the two gimbal lock orientations that only applies to the euler angles representation. At this rotation euler angles will loose one of the three degrees of freedom. Quaternions don’t suffer from gimbal lock, but euler angles do.

Your whole code looks a bit suspicious. Why do you have your new up direction in local space?
Also this: transform.TransformDirection(Vector3.up) is a confoluted way to write transform.up

Be careful when printing out vector3 values. Unity by default rounds the numbers to one decimal place. You can pass a number format to the ToString method to specify a higher precision.

I have the new up direction converted to world space I think (didn’t know about transform.up thanks!)

// Summary:
// Transforms direction from local space to world space.
//
// Parameters:
// direction:
public Vector3 TransformDirection(Vector3 direction);

Just to explain what I’m trying to do - I’m trying to use arrow inputs as direction to rotate an object 90 degrees on the axis of rotation. The problem is that Quaternion.LookRotation(newForwardDirection, newUpDirection); is not producing a rotation exactly at 90 degree intervals (but close). The issue is fixed if I use RoundToInt but seems hacky.