How to Lerp Rotation

I have a script that lets you shake a tree, and after a few shakes I want the tree’s rotation to return to normal. The issue is, I have it Lerp, it works fine if the branches are rotating counter-clockwise, but if it’s rotated clockwise, it will rotate clockwise to correct it’s rotation, it doesn’t rotate counter-clockwise.

Here’s my code,

        if(!treeShaking && resetTime)
        {
            treeLeaves.eulerAngles = Vector3.Lerp(treeLeaves.eulerAngles, Vector3.zero, smoothSpeed * Time.deltaTime);
            treeLog.eulerAngles = Vector3.Lerp(treeLog.eulerAngles, Vector3.zero, smoothSpeed * Time.deltaTime);
            treeLog.position = Vector3.Lerp(treeLog.position, originalPos, smoothSpeed * Time.deltaTime);
            if (treeLeaves.eulerAngles == Vector3.zero && treeLog.position == originalPos)
            {
                resetTime = false;
            }
        }

Is there any way to make it rotate counter-clockwise if the rotation is clockwise and vice versa?

Thanks in advance

transform.rotation = Quaternion.Lerp(rotationA, rotationB, progress); // where progress is a float with a value from 0 to 1
1 Like

Ahhh, I didn’t know Quaternion had a built-in Lerp function haha, thank you!

1 Like

The primary reason that most 3D engines use quaternions for rotations is that Euler angles don’t interpolate well.

1 Like