Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Freelook camera jumpy rotation when rotating in lower framerates

Discussion in 'Cinemachine' started by Eg1l, Jun 14, 2022.

  1. Eg1l

    Eg1l

    Joined:
    Sep 28, 2015
    Posts:
    11
    Hi!

    I've come across a strange camera rotation behavior using Cinemachine Freelook.
    Not all parts of our game have perfect 60 fps, so frame dips are expected, at least for some users.

    Rotating the Freelook camera still result in the camera direction is more jumpy or jittery than expected.
    (Tested also without a moving character just by setting Follow and LookAt on a stationary gamebject).

    By jittering I mean that the camera tends to move in a staircase pattern rather than a diagonal when inputting for example .5f on x-axis and .5f on y-axis. It sometimes seems like the rotation movement jumps ahead of its expected movement. Comparing to other simpler camera rotations, the cameras still end up where you expect them to because input updates are done in the update-loop including Time.deltatime.

    Settings:
    The cinemachine brain is set to update on LateUpdate.
    Freelook uses InputValueGain for both axis and I have tried updating the axis value both by manually setting them in update or using an extension RewiredCinemachineBridge but no difference there.
    I have tried with and without using CinemachineCameraOffset.

    Uploaded a screenshot of all the Freelook settings.

    Scrolling through the forum for similar thread, all I found was something about InputValueGain having a framerate dependant bug. But I didn't seem to get better results using MaxSpeed. Could this be related?
    https://forum.unity.com/threads/tim...ime-scale-fixed-timestep.587386/#post-8103827

    I am thankful for any leads!
     

    Attached Files:

  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Hi
    Could you show a recording of the jittery rotation, or send us a sample project where we can reproduce it?
    What Cinemachine and Unity version are you using?
     
  3. Eg1l

    Eg1l

    Joined:
    Sep 28, 2015
    Posts:
    11
    I can try to set up a sample project.
    Currently using Cinemachine Version 2.9.0-pre.6 and Unity 2021.2.19f1
     
  4. Eg1l

    Eg1l

    Joined:
    Sep 28, 2015
    Posts:
    11
    I have sent you a repro sample project with a simple camera controller sending joystick input to the freelook input axis values. On one side of the "character" there is a large collection of meshes alpha textures generating a lot of drawcalls. Feel free to multiply these if you happen to be on a powerful pc.

    The effect is most noticable in the build as opposed to in the editor window. And the jittering is most visible when rotating the camera in diagonals, as it seems like the Y-axis blends differently between the orbitals than rotating the X-axis. Lower framerate is of course expected to give choppy camera rotations, but the staircase pattern seen when rotating diagonally stands out as something different.
     
    gaborkb likes this.
  5. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    160
    Are you using the input system package?
     
  6. Eg1l

    Eg1l

    Joined:
    Sep 28, 2015
    Posts:
    11
    We are using Rewired for our project, but for the sample repro project I've just set up Input.GetAxis(..) and use that for the
    m_XAxis.m_InputAxisValue together with deltaTime.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    I had a look at your project, and I think the problem is in your CameraController script.

    When you set AxisState.m_InputAxisValue you should not be applying deltaTime, because the FreeLook will do that when processing the input value. As a result deltaTime is being squared. When I change your script to scale the input by a constant value, there is no unevenness in the motion.

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class CameraController : MonoBehaviour
    5. {
    6.     public CinemachineFreeLook freelook;
    7.     public float Gain = 0.01f;
    8.    
    9.     // Update is called once per frame
    10.     void Update()
    11.     {
    12.         var inputX = Input.GetAxis("Horizontal");
    13.         freelook.m_XAxis.m_InputAxisValue = inputX * Gain;
    14.            
    15.         var inputY = Input.GetAxis("Vertical");
    16.         freelook.m_YAxis.m_InputAxisValue = inputY * Gain;
    17.     }
    18. }
    19.  
    You would need to consider deltaTime if you were driving AxisState.Value directly.
     
  8. GamesArtStudio

    GamesArtStudio

    Joined:
    Feb 18, 2022
    Posts:
    1
    I am facing the same issue when rotating the camera diagonally it feels jittery

     
    Last edited: May 28, 2023