[REQUEST]Allow users to choose to update the camera in LateUpdate or FixedUpdate.

WeiYiHua

Member
Third Person Controller 3.0.4.

Updating the camera in FixedUpdate will never be smoother than in LateUpdate. So I try to update camera in LateUpdate and it works fine.

I made these changes to get it done:
1. Modify the update camera in SimulationManager.
Code:
/// <summary>
/// Executes physical simulation during the FixedUpdate loop.
/// </summary>
private void FixedUpdate()
{
    MoveKinematicObjects();

    MoveCharacters();
}

/// <summary>
/// Executes Cameras update during the LateUpdate loop.
/// </summary>
private void LateUpdate()
{
    RotateCameras();

    MoveCameras();
}

2. Interpolate the character's Rigidbody.

3. Change the Update Mode of the character's Animator to Normal.

4. Modify the character IK.
Code:
/// <summary>
/// Updates the hip position during the FixedUpdate loop.
/// </summary>
public void FixedUpdate()
{
    if (m_Animator.updateMode == AnimatorUpdateMode.AnimatePhysics)
    {
        m_Hips.position = m_Transform.TransformPoint(m_HipsPosition);
    }
}

/// <summary>
/// Updates the IK component after the animator has updated.
/// </summary>
public void LateUpdate()
{
    if (m_Animator.updateMode != AnimatorUpdateMode.AnimatePhysics)
    {
        m_Hips.position = m_Transform.TransformPoint(m_HipsPosition);
    }

    // After the IK has finished positioning the limbs for the first time reset the immediate position. It should smoothly blend
    // during runtime.
    if (m_ImmediatePosition)
    {
        m_ImmediatePosition = false;
    }
}

5. I implemented my own MovementType and ViewType.

After doing this, everything is smooth. Both high and low frame rates feel great.
This proves that this feature is fully achievable, please improve it to make the controller more optional, thanks.
 
1671008145409.png
But it should also be noted that Time.deltaTime is not affected by Time.timeScale in FixedUpdate, and is affected by Time.timeScale in Update.
 
I found when updating the camera within LateUpdate and having a FixedUpdate character it doesn't give smooth results. With a FixedUpdate camera it should give smooth results for both high and low framerates. Were you experiencing otherwise?
 
I used Cinemachine and set it to SmartUpdate, Rigidbody applied interpolation, maybe Cinemachine update it differently? As far as the results go, that's pretty good.
1671024506545.png
1671024540882.png
 
Last edited:
There is one more change when I use Cinemachine: the camera Transform is only controlled by Cinemachine.
CameraController.cs
1671024951728.png
 
If you have a monitor with a high refresh rate such as 144Hz, you should feel a big difference compared to FixedUpdate.
 
Last edited:
Ahh, using Cinemachine. Ok, that makes more sense. I haven't had a chance to dive into the Cinemachine integration yet but will take a closer look at this when I do so.
 
Top