How can I smoothly interpolate between different height and radius values?

Hello everyone,

I’m currently developing a prototype where the player becomes bigger (the physical scale increases) after a certain event occurs. I’m using a third-person freelook camera, and I’ve also made it so that the height and radius of each rig become larger with the player, making a sort of “zoom out” effect. The problem is that this change happens instantly and not smoothly. This is what my code looks like:

// Update is called once per frame
    void Update()
    {
        CalculateForward();
        RotatePlayerToInput();
        AdjustCameraDistance();
    }

And this is the function responsible for scaling the heights and radii of each rig:

void AdjustCameraDistance() {
        if (!radiusUpdated) {
            for (int i = 0; i < 3; i++) {
                // When the player gets bigger, multiply the heights and radii of the freelook cam.
                // This will make a "zoom out" effect.
                freelook.m_Orbits[i].m_Height *= cameraDistanceMultiplier;
                freelook.m_Orbits[i].m_Radius *= cameraDistanceMultiplier;
            }
            radiusUpdated = true;
        }
    }

I tried using Mathf.Lerp when assigning the new height and radius values, but it didn’t have any effect. For example, freelook.m_Orbits[i].m_Height = Mathf.Lerp(freelook.m_Orbits[i].m_Height, freelook.m_Orbits[i].m_Height * cameraDistanceMultiplier, smoothTime * Time.deltaTime); This didn’t do anything.
Do you guys have any ideas on how I can get this to work?

You’re not using Lerp correctly. The last parameter must be from 0…1. Try using SmoothDamp instead. Note that you must call this over multiple frames, until the target radius is reached.

1 Like

Yep, I asked a similar question about lerping an object’s scale in another thread and successfully got it to work using a coroutine. Thank you!