Search Unity

Resolved Correctly handling both mouse and stick input.

Discussion in 'Input System' started by chemicalcrux, Mar 27, 2023.

  1. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    721
    I realized that I've been misusing mouse delta input for a while now. Since it's an absolute value, it should not be scaled by deltaTime when determining how much to move the camera. This contrasts with the relative value of a gamepad's stick.

    If you multiply the mouse input by deltaTime, you wind up making your view sensitivity framerate-dependent. oops!

    The solution I worked out has been to check if the active control is a mouse...

    Code (CSharp):
    1.         latestLook = lookAction.action.ReadValue<Vector2>();
    2.  
    3.         if (lookAction.action.activeControl != null)
    4.         {
    5.             if (lookAction.action.activeControl.device.description.deviceClass == "Mouse")
    6.                 latestLook /= 60;
    7.             else
    8.                 latestLook *= Time.deltaTime;
    9.         }
    This is kind of fiddly. Does the Input System have a way to abstract this away, so that the value of the action is always an absolute amount of movement?
     
  2. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    721
    Giving this a bump, since I ran into someone having this problem on the forum recently :)

    I think this would be straightforward if I could check if a particular control is a delta or not. I guess I could just directly check for "Delta" in the control path?
     
  3. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    721
    Ah, I just found this post, which suggests using a processor. That's exactly what I needed here! I've written custom processors before, but didn't think of it for this case...
     
    Gregoryl likes this.