Search Unity

Bug Cinemachine virtual camera rotates faster depending on the FPS

Discussion in 'Cinemachine' started by Mudias, Sep 5, 2022.

  1. Mudias

    Mudias

    Joined:
    Jan 19, 2019
    Posts:
    5
    Rotating the virtual camera is way too fast with the mouse when the FPS is low, and its at a decent speed when the FPS is high. Also sometimes it randomly rotates even faster for a second no matter how high the FPS is. However the FPS doesn't affect the gamepad's rotation speed. When I change the cinemachine brain's Update method from Smart Update to Fixed Update it kinda fixes the fps problem but then the camera still rotates faster for a second sometimes. How can I fix this problem?

    Unity 2021.3.8f1
    Input System 1.4.2
    Cinemachine 2.8.9
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    That's because the default Input Actions that ship with the input system do not deliver the same kind of values for mouse delta as they do for other devices, so it's impossible for Cinemachine to handle both kinds of input agnostically.

    The key issue is that mouse deltas will be larger for low framerates and smaller for high framerates. This is not the case for other kinds of input, so Cinemachine cannot compensate for it without knowing too much detail about the input source - which would break the abstraction that the input package brings.

    One possible fix is to implement a processor for the mouse delta binding in the input system. The processor needs to scale the input by the inverse of deltaTime, making it framerate-independent. Here is an example of a custom processor that does that. Add it to your project, then add the processor to the mouse delta binding of the input action, as shown below.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. /// <summary>
    5. /// This processor scales the value by the inverse of deltaTime.
    6. /// It's useful for time-normalizing framerate-sensitive inputs such as pointer delta.
    7. /// </summary>
    8. #if UNITY_EDITOR
    9. [UnityEditor.InitializeOnLoad]
    10. #endif
    11. class DeltaTimeScaleProcessor : InputProcessor<Vector2>
    12. {
    13.     public override Vector2 Process(Vector2 value, InputControl control) => value / Time.unscaledDeltaTime;
    14.  
    15.     #if UNITY_EDITOR
    16.     static DeltaTimeScaleProcessor() => Initialize();
    17.     #endif
    18.  
    19.     [RuntimeInitializeOnLoadMethod]
    20.     static void Initialize() => InputSystem.RegisterProcessor<DeltaTimeScaleProcessor>();
    21. }
    22.  
    upload_2022-9-13_16-52-54.png

    If your camera is bound to a read-only input action from the DefaultInputActions asset, you'll first need to copy that asset into your project so that you can modify it, then re-assign the input actions to the camera.
     
    Last edited: Sep 14, 2022
    gaborkb likes this.