Sunday, June 12, 2022
HomeGame Developmentunity - Why rotating backwards is simply too quick, even when I...

unity – Why rotating backwards is simply too quick, even when I set the time to three seconds?


The rotation could be very quick. It takes lower than a second and for certain not 3 seconds.

Possibly it is higher to do it with out utilizing a coroutine? Or one thing within the IEnumerator is improper with the time and progress calculation?

public IEnumerator DoRotate(float time)
{
    var newRotation = Quaternion.AngleAxis(180, Vector3.up) * rework.rotation;

    var progress = 0f;

    whereas (progress < 1)
    {
        progress += Time.deltaTime / time;

        rework.rotation = Quaternion.Slerp(rework.rotation, newRotation, progress);

        yield return new WaitForEndOfFrame();
    }
}

Utilization :

personal void FixedUpdate()
{
    if (rotateBackwards)
    {
        StartCoroutine(DoRotate(3f));
        rotateBackwards = false;
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments