Search Unity

Question Warping with mouse delta

Discussion in 'Input System' started by Dr_SuiuS, Nov 19, 2020.

  1. Dr_SuiuS

    Dr_SuiuS

    Joined:
    Jun 20, 2019
    Posts:
    7
    ezgif.com-gif-maker.gif
    Having this problem for half a year now.
    Slight warps happen once every 4-5 seconds and it significantly affects the rotation in the game view. The problem persists in the build, but warps become much smaller. Tried setting target framerate, different action types and different control types - neither one of these affected the warping.
    I send Unity Events to my rotation scripts: rotationX and rotationY.
    Both scripts are almost the same, only difference is the axis along which the script rotates the transform.

    Code (CSharp):
    1. public class XRotation : MonoBehaviour
    2. {
    3.     [SerializeField] float rotationMultiplier;
    4.     // Damping
    5.     [Header("0 to disable")]
    6.     [Range(0f, 360f)]
    7.     [SerializeField] float damping;
    8.  
    9.     float xAxis;
    10.  
    11.     /// <summary>
    12.     /// Executed when script becomes awake
    13.     /// </summary>
    14.     private void Awake()
    15.     {
    16.         xAxis = 0;
    17.     }
    18.  
    19.     public void ChangeXAxis(InputAction.CallbackContext ctx)
    20.     {
    21.         if (!ctx.started && !ctx.canceled && ctx.performed)
    22.         {
    23.             xAxis += ctx.ReadValue<float>() * rotationMultiplier;
    24.         }
    25.     }
    26.  
    27.     /// <summary>
    28.     /// Executed once a frame
    29.     /// </summary>
    30.     void Update()
    31.     {
    32.         if (damping != 0)
    33.         {
    34.             xAxis = Mathf.Clamp(xAxis, -damping, damping);
    35.         }
    36.         transform.localRotation = Quaternion.Euler(Vector3.up * xAxis);
    37.     }
    38. }
    Code (CSharp):
    1. public class YRotation : MonoBehaviour
    2. {
    3.     [SerializeField] float rotationMultiplier;
    4.     // Damping
    5.     [Header("0 to disable")]
    6.     [Range(0f, 360f)]
    7.     [SerializeField] float damping;
    8.  
    9.     float yAxis;
    10.  
    11.     /// <summary>
    12.     /// Executed when script becomes awake
    13.     /// </summary>
    14.     private void Awake()
    15.     {
    16.         yAxis = 0;
    17.     }
    18.  
    19.     public void ChangeYAxis(InputAction.CallbackContext ctx)
    20.     {
    21.         if (!ctx.started && !ctx.canceled && ctx.performed)
    22.         {
    23.             yAxis += ctx.ReadValue<float>() * rotationMultiplier;
    24.         }
    25.     }
    26.  
    27.     /// <summary>
    28.     /// Executed once a frame
    29.     /// </summary>
    30.     void Update()
    31.     {
    32.         if (damping != 0)
    33.         {
    34.             yAxis = Mathf.Clamp(yAxis, -damping, damping);
    35.         }
    36.         transform.localRotation = Quaternion.Euler(Vector3.left * yAxis);
    37.     }
    38. }
    39.  
    My Input Actions asset:
    2020-11-19.png
    LookX and LookY are pass through and have Any control type.
    Not using any processors or interactions.

    I would really like to get rid of this warping, as I like the new Input System very much and I don't want to return back to the old one.
    Thank you.

    UPDATE 1:
    Found out that setting target framerate to 60 with Application.targetFrameRate makes the warping much less noticeable, but then mouse doesn't move as smoothly as it does without the set target frame rate.
     
    Last edited: Nov 22, 2020