Rotation by 90 degrees not exactly 90


I have this piece of code:

y = transform.rotation.y - 90;

It happens when I press the D key. it should instantly turn 90 degrees. problem is it turns 90.435 degrees or something. never a clean 90. So slowly but surely the rotation gets all messed up. Is there a fix for this?

Transform.rotation returns a Quaternion, so I’m honestly more amazed it happens to be coming out close to what you’re shooting for.

To get the result you’re actually looking for, you could try using something like:

transform.eulerAngles += Vector3.up * -90f;


transform.rotation *= Quaternion.AngleAxis(-90f, Vector3.up);