Search Unity

Bug [Freelook Camera] Inconsistent behaviour between Mouse Delta and Gamepad Right Stick

Discussion in 'Cinemachine' started by Bezoro, Aug 25, 2022.

  1. Bezoro

    Bezoro

    Joined:
    Mar 16, 2015
    Posts:
    133
    When using the mouse to rotate the freelook camera it behaves as expected, regardless of the framerate.
    When using the gamepad's right stick to rotate the freelook camera it rotates faster the higher the framerate.

    When setting the Cinemachine Brain to Fixed Update it works as expected but then adds other issues. (Mouse rotation becomes inconsistent regardless of framerate and movement gets very choppy due to unsynchronized character/camera updates).

    Cinemachine: 2.8.6
    InputSystem: 1.4.2


    Cinemachine Brain:
    cinemachine brain.png

    Freelook Camera:
    freelook camera.png

    Look Inputs:
    look.png mouse delta.png right stick.png
     
  2. Bezoro

    Bezoro

    Joined:
    Mar 16, 2015
    Posts:
    133
    Ended up working around it with custom code instead of using the cinemachine input provider.

    From what I can tell, Smart Update is using LateUpdate under the hood.
    Therefore there must not be any code to make the input getting fed into the system framerate independent.
    Simply multiplying the look input by Time.deltaTime should fix the issue. I tried but couldn't find exactly where the input was being applied.
     
    Last edited: Aug 25, 2022
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Cinemachine is applying deltaTime in the appropriate places.
    Do you have this input setting set?

    upload_2022-8-26_11-17-7.png
     
    Mudias likes this.
  4. Bezoro

    Bezoro

    Joined:
    Mar 16, 2015
    Posts:
    133
    Hey, thank you for taking the time.
    Yes, the input system is set to process events in dynamic update.

    Just so you know this is my code, which ended up giving me framerate independent look rotation for both mouse and right stick alike.
    Its in LateUpdate(). And the Cinemachinebrain is also set to use Late Update, since that is what gives me flawless results with Kinematic Character Controller.

    Code (CSharp):
    1. var xInverted = 1;
    2. var yInverted = 1;
    3.  
    4. if (characterFreeLookCamera.m_XAxis.m_InvertInput)
    5.    xInverted = -1;
    6. if (characterFreeLookCamera.m_YAxis.m_InvertInput)
    7.    yInverted = -1;
    8.  
    9. characterFreeLookCamera.m_XAxis.Value += LookInputVector.x * characterFreeLookCamera.m_XAxis.m_MaxSpeed * xInverted * Time.deltaTime;
    10.  
    11. characterFreeLookCamera.m_YAxis.Value += LookInputVector.y * characterFreeLookCamera.m_YAxis.m_MaxSpeed * yInverted * Time.deltaTime;
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Thanks for the info. I don't have a working gamepad at my home office, so can't check it myself. I've ordered a new one, should arrive within a couple of weeks. I'll get back to you.
     
    Bezoro likes this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Got the gamepad and checked. You are right! DeltaTime is not in fact being applied properly in CM's input handling. We will make a fix.
     
    Bezoro likes this.
  7. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    353
    Can you pls Update Here If the fix is out?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    This has been fixed in the most recent CM version.
     
  9. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    107
    Sorry for reviving this thread, but I am using Unity 2021.3.22f1 with Cinemachine 2.9.5 and my stick input is unfortunately also frame rate-dependent. Attached are some screenshots of my setup:
    2304211715.png

    Edit: Here is a short video about the difference:

    https://imgur.com/a/u0frch0

    Edit2: Fixed it with the delta time processor by @antoinecharton

    https://forum.unity.com/threads/why...era-framerate-dependant.1419530/#post-8924786
     
    Last edited: Apr 21, 2023
    Gregoryl and antoinecharton like this.
  10. JoshChristiane

    JoshChristiane

    Joined:
    Aug 11, 2021
    Posts:
    3
    Yeah this is still an issue that hasn't been fixed. I'm on Unity 2022.3.6f1 using Cinemachine 2.9.7 and the gamepad controller input is framerate dependent still. I'm going to apply the custom delta time processor as recommended by others, but this probably should get fixed.