- Home /
Can't Change Objects Rotation
So, I have object, and then player doesn't do anything, it spins in place: gameObject.transform.Rotate(rotationSpeed * Time.deltaTime, rotationSpeed * Time.deltaTime, rotationSpeed * Time.deltaTime);
. And I want when player touches object, it would get back to its start rotation form, using: gameObject.transform.Rotate(0, 0, 0);
, but the thing is, that doesn't work. Gameobject is still rotated. ( I also made, then player touches object, it will not rotate, that doesn't work) Does anybody know how to fix that?
Answer by $$anonymous$$ · Nov 12, 2020 at 08:26 AM
Essentially, gameObject.transform.Rotate(0, 0, 0) tells the object to rotate by 0 degrees, so it won't rotate at all. What you want is to lerp the rotation back to 0, like this:
float lerpSpeed = 0.125; // A random number
transform.rotation = Quaternion.lerp(transform.rotation, Quaternion.Euler(Vector3.zero), lerpSpeed);
Of note, Quaternion.Euler(Vector3.zero) would result in the same value as Quaternion.identity. With that in $$anonymous$$d, an immediate rotation change could be:
transform.rotation = Quaternion.identity;
(or the target rotation in a Lerp/Slerp rotation could be defined as Quaternion.identity instead)