Search Unity

Jitter Issue for Freelock Camera

Discussion in 'Cinemachine' started by ewinia, Apr 6, 2021.

  1. ewinia

    ewinia

    Joined:
    Apr 6, 2014
    Posts:
    3
    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?



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Cinemachine;
    5.  
    6. public class FreelockCamera : MonoBehaviour
    7. {
    8.     [SerializeField]
    9.     private CinemachineFreeLook freeLockCamera = null;
    10.     [SerializeField]
    11.     private float verticalMoveSpeedForEditor = 0.6f;
    12.  
    13.     private float scrollValueSum = 0.0f;
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         float scrollValue = Input.GetAxis("Mouse ScrollWheel");
    19.         scrollValueSum += scrollValue;
    20.     }
    21.  
    22.     private void FixedUpdate()
    23.     {
    24.         if (scrollValueSum != 0)
    25.         {
    26.             freeLockCamera.m_YAxis.Value += scrollValueSum * verticalMoveSpeedForEditor;
    27.             scrollValueSum = 0.0f;
    28.         }
    29.     }
    30. }
    31.  
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    I can't reproduce your problem with the script you posted.
    Can you post a small repro project?
     
    ewinia likes this.
  3. ewinia

    ewinia

    Joined:
    Apr 6, 2014
    Posts:
    3

    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.
     

    Attached Files:

    Gregoryl likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Thanks for the upload. I see the problem now.
    There were a couple of issues.
    1. You had the FreeLook as a component on the Main Camera. Don't do that. FreeLook should be a separate Game object.
    2. 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:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Cinemachine;
    5.  
    6. public class FreelockCamera : MonoBehaviour, AxisState.IInputAxisProvider
    7. {
    8.     [SerializeField]
    9.     private float verticalMoveSpeedForEditor = 0.6f;
    10.  
    11.     private float scrollValueSum = 0.0f;
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         float scrollValue = Input.GetAxis("Mouse ScrollWheel");
    17.         scrollValueSum += scrollValue;
    18.     }
    19.  
    20.     public float GetAxisValue(int axis)
    21.     {
    22.         float value = 0;
    23.         // 0 == x axis, 1 == Y axis, 2 == z axis
    24.         if (axis == 1)
    25.         {
    26.             value = scrollValueSum * verticalMoveSpeedForEditor;
    27.             scrollValueSum = 0.0f;
    28.         }
    29.         return value;
    30.     }
    31. }
    32.  
    Also, I've attached an updated version of your project, with everything set up correctly.
     

    Attached Files:

    ewinia likes this.
  5. ewinia

    ewinia

    Joined:
    Apr 6, 2014
    Posts:
    3
    Thanks to you, I was able to solve the problem safely!
     
    Gregoryl likes this.