Search Unity

Why does my FPS camera rotates faster on lower frame rates?

Discussion in 'Input System' started by Luemus, Feb 24, 2021.

  1. Luemus

    Luemus

    Joined:
    May 20, 2013
    Posts:
    107
    I have a simple first-person controller setup and today I've noticed that the camera becomes more sensitive on lower frame rates. Here is the setup and code that I use:

    Code (CSharp):
    1.     private void Start()
    2.     {
    3. //...
    4.         _inputActionMap.FindAction("Look").performed +=
    5.             context => ProcessCamera(context.ReadValue<Vector2>());
    6. //...
    7. }
    Code (CSharp):
    1.     private void ProcessCamera(Vector2 direction)
    2.     {
    3.         var mouseX = direction.x * cameraSensitivity;
    4.         var mouseY = direction.y * cameraSensitivity;
    5.  
    6.         _cameraXRotation -= mouseY;
    7.         _cameraXRotation = Mathf.Clamp(_cameraXRotation, -80, 80);
    8.        
    9.         playerCamera.localRotation = Quaternion.Euler(_cameraXRotation, 0, 0);
    10.         playerBody.Rotate(Vector3.up * mouseX);
    11.     }
    upload_2021-2-24_18-8-1.png
     
  2. Luemus

    Luemus

    Joined:
    May 20, 2013
    Posts:
    107
  3. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
    Delta [Pointer] is not normalize by default, its mean the value greater than 1 or lesser than -1, multiply by sensitivity and that is cost a large scale of movement

    this is how i fix my delta
     
    Luemus likes this.
  4. Luemus

    Luemus

    Joined:
    May 20, 2013
    Posts:
    107
    Oh, I didn't know that it wasn't normalized. Thanks a lot, however, it doesn't feel as smooth/responsive as it used to be now. Any ideas on improving that?
     
  5. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
    i dont know what kind of camera rotation technique you are using, but here some API for most common use for smooth

    for vector 2
    https://docs.unity3d.com/ScriptReference/Vector2.SmoothDamp.html
    for single axis Float
    https://docs.unity3d.com/ScriptReference/Mathf.SmoothDampAngle.html
    for quaternion
    https://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html
    or
    https://docs.unity3d.com/ScriptReference/Quaternion.SlerpUnclamped.html

    i recommend to try Mathf.SmoothDamp for mouseX and mousY
    https://docs.unity3d.com/ScriptReference/Mathf.SmoothDamp.html
     
    Last edited: Feb 25, 2021
    Luemus likes this.