- Home /
Rotation by 90 degrees not exactly 90
Hi,
I have this piece of code:
y = transform.rotation.y - 90;
transform.Rotate(0,y,0);
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?
Comment
Best Answer
Answer by Eno-Khaon · Oct 27, 2020 at 09:48 AM
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;
or
transform.rotation *= Quaternion.AngleAxis(-90f, Vector3.up);
Perfect, it worked :D thank you. Will read about quaternions than :)