Jitter Issue for Freelock Camera

While using the freelock camera, there was a jitter issue.

Both look at target and follow target point to player.
The TopRig MiddleRig BottomRig set as a composer has a different Tracked Object Offset.

In that state, if you modify the y-axis in the script, there is an issue where the angle of the camera is first turned off and the position is moved one beat late, does anyone know the solution?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class FreelockCamera : MonoBehaviour
{
    [SerializeField]
    private CinemachineFreeLook freeLockCamera = null;
    [SerializeField]
    private float verticalMoveSpeedForEditor = 0.6f;

    private float scrollValueSum = 0.0f;

    // Update is called once per frame
    void Update()
    {
        float scrollValue = Input.GetAxis("Mouse ScrollWheel");
        scrollValueSum += scrollValue;
    }

    private void FixedUpdate()
    {
        if (scrollValueSum != 0)
        {
            freeLockCamera.m_YAxis.Value += scrollValueSum * verticalMoveSpeedForEditor;
            scrollValueSum = 0.0f;
        }
    }
}

I can’t reproduce your problem with the script you posted.
Can you post a small repro project?

1 Like

ok

If you open the SampleScene of this project and zoom in with the mouse scroll, you will see the right side of the red cube shaking.

7010644–829357–Cinemachine.zip (25.3 KB)

1 Like

Thanks for the upload. I see the problem now.
There were a couple of issues.

  • You had the FreeLook as a component on the Main Camera. Don’t do that. FreeLook should be a separate Game object.
  • Your custom script is intended to provide input for the FreeLook. That plays best when you have the script implement the AxisState.IInputAxisProvider interface, allowing the FreeLook to query it at the right moment

Here is an updated version of your script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class FreelockCamera : MonoBehaviour, AxisState.IInputAxisProvider
{
    [SerializeField]
    private float verticalMoveSpeedForEditor = 0.6f;

    private float scrollValueSum = 0.0f;

    // Update is called once per frame
    void Update()
    {
        float scrollValue = Input.GetAxis("Mouse ScrollWheel");
        scrollValueSum += scrollValue;
    }

    public float GetAxisValue(int axis)
    {
        float value = 0;
        // 0 == x axis, 1 == Y axis, 2 == z axis
        if (axis == 1)
        {
            value = scrollValueSum * verticalMoveSpeedForEditor;
            scrollValueSum = 0.0f;
        }
        return value;
    }
}

Also, I’ve attached an updated version of your project, with everything set up correctly.

7010794–829387–CinemachineFreeLookJitter.zip (27.8 KB)

1 Like

Thanks to you, I was able to solve the problem safely!

1 Like