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. Dismiss Notice

Bug Why is CinemachineFreeLook Camera framerate dependant ?

Discussion in 'Cinemachine' started by SIgmar_Storm, Mar 31, 2023.

  1. SIgmar_Storm

    SIgmar_Storm

    Joined:
    Jul 3, 2020
    Posts:
    5
    Hi guys,

    I'm using a third person cinemachine free look camera in my game and it seems to be framerate dependant when I test it.
    I have an option to activate VSync or not (if On, it changes FPS to feat screen Hz).

    If option is Off (so many FPS), camera movement are normal.
    If option is On (so 60 FPS) camera movement are very slow.

    I'm using Cinemachine 2.9.5 on Unity 2021.3.20.
    Parameters used :
    • Input Value Gain for each Axis.
    • X axis Speed to 1 and Accel/Decel time to 0.01
    • Y axis with 0.015 Speed and Accel/Decel time to0.05
    • New Input system and Cinemachine Input provider.
    • Cinemachine Brain Update method to Smart Update (others create some shuderring)
    I have read all potentials Issues on this subject but nothing for me.
    What I have already tried :
    • Create a processor for Input system to decrease inputs using deltatime
    • Modify GetAxisValue return value in Custom Input Provider
    Have you some ideas on this please ?
    Thanks guys.
     
  2. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    Hey @SIgmar_Storm.

    [Previous post (Replied a bit to fast)]
    It's a regression :/ we fixed and came back. Will be fixed ASAP. Thanks for reporting it.

    [Edit]
    Looks like it's not the bug we previously had. Do you think you could be able to do a repro project of the issue with one VCam?

    Let us know
     
    Last edited: Mar 31, 2023
    Wolkand likes this.
  3. SIgmar_Storm

    SIgmar_Storm

    Joined:
    Jul 3, 2020
    Posts:
    5
    Hi, thanks for reply.

    I've realised a test project with the same parameters listed above.
    It seems to come from Input provider when using gamepad, mouse seems to be OK, but Gamepad mode is not.

    You can test the build given in this zip with the rest of the project.
    WeTransfer link https://we.tl/t-YFm9vN9HiO, this forum not allow big Zip file.

    To reproduce,
    • Open the build given with the zip project
    • Just put the gamepad right stick to right/left side => Get the sensitivity in mind
    • Press F1 Key on your keyboard (Enable/Disable VSync)
    • Put again the gamepad right stick to a side => Slower than before.
    Thanks
     
    antoinecharton likes this.
  4. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    Hi again :) ,

    The problem is controller joystick is not delta timed. For example:
    - If your stick on the right at 10 fps it will be updated 10 * 1 per seconds = 10 units.
    - With the stick on the right at 100 fps it will be updated 100 * 1 per seconds = 100 units.

    Why doesn't it happen with the mouse?
    If you are at 10 fps or 100 fps moving physically the mouse 100 inch to the right the delta per frame will change but the total delta per second will be the same.

    How to solve it?
    We will see with the team if there is a way to improve this use case in a better way. The frame based joystick value makes sense in some use case and doesn't in others.

    In your case specifically you could use processors to make the joystick value delta timed. Simplest way would be to create a processor.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3. #if UNITY_EDITOR
    4. using UnityEditor;
    5. [InitializeOnLoad]
    6. #endif
    7. public class DeltaTimeProcessor : InputProcessor<Vector2>
    8. {
    9. #if UNITY_EDITOR
    10.     static DeltaTimeProcessor()
    11.     {
    12.         Initialize();
    13.     }
    14. #endif
    15.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    16.     static void Initialize()
    17.     {
    18.         InputSystem.RegisterProcessor<DeltaTimeProcessor>();
    19.     }
    20.     public override Vector2 Process(Vector2 value, InputControl control)
    21.     {
    22.         return value * Time.deltaTime;
    23.     }
    24. }
    And add this processor to your joystick action.
    Screen Shot 2023-04-03 at 2.41.52 PM.png

    Let us know if this work for you.
     
    Wolkand, Bezoro, baumxyz and 2 others like this.
  5. SIgmar_Storm

    SIgmar_Storm

    Joined:
    Jul 3, 2020
    Posts:
    5
    Hi !

    Thanks for the solution, it seems to work for the Test project.
    I had already create and test this type of processor, but it was not working...

    ..and I know why :

    During few tests I found a bug in Input Action Asset.

    When you add a processor and save the input asset, sometimes the processor disappears.
    I had to do it 5 times to have the processor saved with the inputs.

    That's why my previous try with processor failed, it was not saved :(

    Thanks
     
    antoinecharton likes this.
  6. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    Awesome you got it working!

    Reported your issue with the input asset to the input team.

    :)
     
    Wolkand likes this.
  7. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    717
  8. Wolkand

    Wolkand

    Joined:
    Jun 23, 2022
    Posts:
    7
    I'm having this exact issue. I tried adding this Processor to the Input System, but then the input doesn't register at all. I did some testing and realized it is the *Time.deltaTime part. If I remove it and add my own multiplier, it works again, but back to depending on framerate. Any ideas?
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    The * Time.deltaTime part is the whole point. What do you mean the input doesn't register? It works for us.
     
    Wolkand likes this.
  10. Wolkand

    Wolkand

    Joined:
    Jun 23, 2022
    Posts:
    7
    Whenever I add the Time.deltaTime the camera just won't respond to input, at all. Without it, it responds slowly but depends on framerate.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3. #if UNITY_EDITOR
    4. using UnityEditor;
    5. [InitializeOnLoad]
    6. #endif
    7. public class DeltaTimeProcessor : InputProcessor<Vector2>
    8. {
    9. #if UNITY_EDITOR
    10.     static DeltaTimeProcessor()
    11.     {
    12.         Initialize();
    13.     }
    14. #endif
    15.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    16.     static void Initialize()
    17.     {
    18.         InputSystem.RegisterProcessor<DeltaTimeProcessor>();
    19.     }
    20.     public override Vector2 Process(Vector2 value, InputControl control)
    21.     {
    22.         return value * Player_Controller.lookStickSensitivity/* * Time.deltaTime*/;
    23.     }
    24. }
    25.  
    I just added my own multiplier so the camera will respond faster, but it does still depend on framerate. The multiplier is a simple float. Whenever I leave the deltaTime, it will stop responding, when I remove it, it works.
     
    Last edited: Aug 10, 2023
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    That should not be happening. The processor is designed specifically to account for the deltaTime.
    Do you have Time.timeScale set to 0?
    Check the Input System Package settings. What is the Update Mode?

    upload_2023-8-15_8-55-20.png
     
    Wolkand and antoinecharton like this.
  12. Wolkand

    Wolkand

    Joined:
    Jun 23, 2022
    Posts:
    7
    Time Scale is set to 1.
    Everything in the Input System Package Settings is exactly as in your screenshot, triple-checked.
     
  13. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    What happens if you add a break point on this line?
    Code (CSharp):
    1.     public override Vector2 Process(Vector2 value, InputControl control)
    2.     {
    3.         return value * Player_Controller.lookStickSensitivity * Time.deltaTime;
    4.     }
    What's the values of Time.deltaTime and Player_Controller.lookStickSensitivity?
     
    Wolkand and Gregoryl like this.
  14. Wolkand

    Wolkand

    Joined:
    Jun 23, 2022
    Posts:
    7
    Breakpoint returns Time.deltaTime as 0.016 at 60fps. Player_Controller.lookStickSensitivity is at 10.
     
  15. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    Hey, no idea what happened with your replies, sorry about that (We can still see automoded stuff).

    Do you think you could create a repro project?
     
    Wolkand likes this.
  16. Wolkand

    Wolkand

    Joined:
    Jun 23, 2022
    Posts:
    7
    Sure, I'll look into it. I will let you know once I upload it somewhere.
     
  17. JoshChristiane

    JoshChristiane

    Joined:
    Aug 11, 2021
    Posts:
    3
    Did you also add a multiplier (scale vector) to the gamepad stick? It will move so slowly after the delta multiplication that it will appear as though it's broken and nothing is happening. It is working but the numbers just become tiny (for obvious reasons). Try adding that scale vector (you might need a huge number ~1000), and see if that helps. Hope you can fix it, that's what worked for me.
     
    Last edited: Aug 18, 2023
    Wolkand and antoinecharton like this.
  18. Wolkand

    Wolkand

    Joined:
    Jun 23, 2022
    Posts:
    7
    I can't seem to catch a break, now I can't upload the repro project to the sharing website. Lol.
     
  19. rshea0

    rshea0

    Joined:
    Jul 23, 2023
    Posts:
    3
    It seems in Cinemachine 2.9.7 the input is always multiplied by deltaTime, this now creates issues for mouse input which is already a delta and shouldn't be multiplied by deltaTime.

    As far as I can tell the only way around this is to directly drive axis.Value.
     
  20. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    With the input system you could use the processor above but with the legacy input system you need to drive it manually indeed.
    Checking if we could make it work without having to do custom code will get back to you.
     
    Wolkand and Lars-Steenhoff like this.
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Here is something you could do when using the legacy input system: you can intercept Cinemachine's GetAxis call and pre-divide by deltaTime for mouse input, something like this:

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class CancelDeltaTimeFoMouseInput : MonoBehaviour
    5. {
    6.     void OnEnable() => CinemachineCore.GetInputAxis = GetAxisCustom;
    7.     void OnDisable() => CinemachineCore.GetInputAxis = Input.GetAxis;
    8.  
    9.     float GetAxisCustom(string axisName)
    10.     {
    11.         var value = Input.GetAxis(axisName);
    12.         if (axisName == "Mouse X" || axisName == "Mouse Y")
    13.             value /= Time.deltaTime;
    14.         return value;
    15.     }
    16. }
    17.  
     
    Wolkand and antoinecharton like this.
  22. Scalisco

    Scalisco

    Joined:
    Feb 2, 2014
    Posts:
    16
    I am also having this problem after upgrading Cinemachine. Controller input is framerate independent, but the mouse is not. Have you found a fix for this?
     
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Yes. If using new input system, add a preprocessor on the mouse delta input to divide by deltaTime. If using legacy input, see my post just above.
     
    Wolkand and Scalisco like this.
  24. Scalisco

    Scalisco

    Joined:
    Feb 2, 2014
    Posts:
    16
    Thank you for the quick reply! That seems to work!

    Is this going to be fixed at some point? Will this processor break after an update at some point?
     
  25. Wolkand

    Wolkand

    Joined:
    Jun 23, 2022
    Posts:
    7
    This:
    plus this:
    worked! It also seemed that I had some conflict regarding parent/child objects within my cameras, because I made some adjustments and now the original Time.deltaTime solution worked! I'm sorry I couldn't upload a repro project. Been hella busy and the times I tried to upload it would get stuck at 99%.. for hours. But it is finally solved for me! I really appreciate the support everyone.
     
  26. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    The processor will continue to work. In CM3, we've added a checkbox to the input controller to control whether deltaTime gets multiplied. That way the processor won't be necessary for mouse input (but it will still work if you don't use the checkbox).
     
    antoinecharton, Scalisco and Wolkand like this.