First time I tried this method:
public IEnumerator DoRotation(float time)
{
var newRotation = Quaternion.AngleAxis(180, Vector3.up) * transform.rotation;
var progress = 0f;
while (progress < 1)
{
progress += Time.deltaTime / time;
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, progress);
yield return new WaitForEndOfFrame();
}
}
Then I used a flag helper inside Update()
to start the coroutine only once but when the transform rotates backwards it also start moving and when moving the transform it shakes/stutters.
I had the same problem with another rotation part and when moving it to FixedUpdate()
it solved the shaking problem.
I'm not sure why it's shaking like that.
I tried this in the FixedUpdate
:
var newRotation = Quaternion.AngleAxis(180, Vector3.up) * transform.rotation;
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * rotationSpeed);
But it keeps rotating the transform 180 degrees the opposite direction nonstop.
How to make the transform rotate backwards in FixedUpdate
instead of in coroutine?