Search Unity

WASD Movement legacy -> Input System (new) - no more interpolation / "sensitivity"?

Discussion in 'Input System' started by MassimoFrancesco, Feb 16, 2020.

  1. MassimoFrancesco

    MassimoFrancesco

    Joined:
    Jul 6, 2019
    Posts:
    44
    Hi,

    tl;dr - I would like to add artificial "sensitivity" to WASD key movement changes in new Input System, like it was available in legacy input system

    I've switched my project from old legacy WASD movement of a third person character to the new Input System.

    New Input system looks and handles great, but there is one major issue I personally have, which makes the gameplay significantly differ from the old legacy setup.

    The legacy Input (GetAxis() in Update()) would feed the two (axis) float values gradually when changing directions.
    Specifically, if you pressed 'S' to move the Character downwards, then additionally pressed 'S'
    + 'A' to move Southwest, the value(s) would not instantly jump, but gradually - making the Character movement change more fluid.
    To my understanding, the "Sensitivity" setting was controlling this behavior in legacy setup:
    upload_2020-2-16_11-52-15.png

    I can't find a possible way to set this up in the new Input System. I'm very likely just missing it. But after a day of toying around with the processors and watching most of the available YT videos on this and official documentation, neither of them addressing it - I'm calling for help here. lol.

    Has anyone run into the same issue yet and knows how to get the more fluid feeling from the legacy system?
     
  2. frarf

    frarf

    Joined:
    Nov 23, 2017
    Posts:
    27
    Just code acceleration yourself, old input acceleration is really limited and messy anyway.
    Your character controller shouldn't be relying on input features...
     
    Iron-Warrior likes this.
  3. MassimoFrancesco

    MassimoFrancesco

    Joined:
    Jul 6, 2019
    Posts:
    44
    So I revisited this issue in my project after some time and not getting it to work earlier, as I'm fairly new to programming.

    For anyone stumbling into the same issue (as this is still not alleviated in the new input system) and finding this thread in search results, here is the code solution:

    Mathf.SmoothDamp

    You still get the movement the usual new way:

     _controls.Player.Movement.performed += ctx => movementInput = ctx.ReadValue<Vector2>().normalized;


    Then instead of feeding the movementInput.x and movementInput.y directly into your RigidBody move logic,
    you SmoothDamp it before, and then feed the newly calculated values.
    Unity Documentation for explanation on each value: https://docs.unity3d.com/ScriptReference/Mathf.SmoothDamp.html

    Beside of Vector2, declare following variables as well:

    Code (CSharp):
    1. Vector2 movementInput;
    2. float smoothTime = 0.3f;
    3. float hVelocity = 0f;
    4. float vVecolity = 0f;
    5. float hCurrent = 0f;
    6. float vCurrent = 0f;
    Then in FixedUpdate(), or whatever suits you best, calculate the SmoothDamp and store it for each direction into a "new" variable. Right after that, set "current" float values equal to the just calculated "new" floats, so the next Update iteration can work with it.

    Code (CSharp):
    1. float newH = Mathf.SmoothDamp(hCurrent, movementInput.x, ref hVelocity, smoothTime);
    2. float newV = Mathf.SmoothDamp(vCurrent, movementInput.y, ref vVecolity, smoothTime);
    3. hCurrent = newH;
    4. vCurrent = newV;
    Then you feed the "new" float variables into your Move logic, or whatever WASD / Controller input logic you want to achieve.

    I hope this is helpful to anyone as well.
     
    Underliinez and kira0x1 like this.
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    This one is indeed missing. It's high up on the list of improvements to the action system.

    To explain a little: currently, processors are required to be stateless. This stems from them being used for both devices/controls *and* actions. And for input controls, due to how they store state, a processor cannot additionally store its own state or trigger inputs when there are none in the event stream.

    However, for actions, this requirement isn't necessary and we intend to explicitly allow and support processors on action bindings to keep local state as well as to add a way for input to be generated by input processors without requiring actual input.
     
    MassimoFrancesco and SomeGuy22 like this.
  5. inScopeStudios

    inScopeStudios

    Joined:
    Oct 2, 2015
    Posts:
    21
    MassimoFrancesco It's actually a great solution. You can also make it into a single line if you use Vector2.SmoothDamp. This code is based on your solution.

    You need to make these field variables:


    Code (CSharp):
    1.     private float animationSmoothTime = 0.3f;
    2.  
    3.     private Vector2 animationVector;
    4.  
    5.     private Vector2 animationVelocity;

    And then you do the following in Update

    Code (CSharp):
    1.   animationVector = Vector2.SmoothDamp(animationVector, movementInput, ref animationVelocity, animationSmoothTime);
    Then you can use the animationVector to make smooth transitions in your Animator.

    Code (CSharp):
    1.   animator.SetFloat("Vertical", animationVector.y);
    2.   animator.SetFloat("Horizontal", animationVector.x);
     
    MassimoFrancesco likes this.
  6. MassimoFrancesco

    MassimoFrancesco

    Joined:
    Jul 6, 2019
    Posts:
    44
    I'm glad this is already on your list. Will be a good improvement.
    I really like the new input system, for what it has to offer so far. It's a huge step forward from the old one. Great job, thank you!