Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How to reproduce the standard Input.GetAxis("Horizontal") in the new input system?

Discussion in 'Input System' started by FeastSC2, Jul 7, 2019.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    865
    How can I have the exact same values given by the Input.GetAxis("Horizontal") that every project has set up by default in Unity in the new Input system?

    I can't seem to reproduce the same values. :(
     
    Bencarbon likes this.
  2. Elhimp

    Elhimp

    Joined:
    Jan 6, 2013
    Posts:
    21
    Code (CSharp):
    1. var myInputAction = inputMap.AddAction("Horizontal");
    2.  
    3. myInputAction.AddCompositeBinding("Axis")
    4. .With("Negative", <Keyboard>/a)
    5. .With("Positive", <Keyboard>/d);
    6.  
    7. myInputAction.passThrough = true;
    Or, do the same with object in inspector
     
  3. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    865
    I should have specified that I want this for a gamepad my bad. Do you know how to replicate the gamepad's horizontal/vertical axis?
     
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    865
    I set the action type to Pass through and the control type to Axis with the left stick[gamepad].
    However the behaviour is just not the same as the Input.GetAxis("horizontal")/("vertical") standard to Unity.

    This is because the input returned by the new input system when I stop holding the joystick is not zero: Sometimes, there is some small value left over like 0.0043.

    I tried to add a processor with Axis Deadzone with a min of 0.1 but it doesn't change anything.

    Here's how I read it in code:
    Code (CSharp):
    1.     public void OnMove(InputAction.CallbackContext context)
    2.     {
    3.         MoveAxis = context.ReadValue<Vector2>();
    4.         Debug.Log("OnMove: " + MoveAxis.ToString("#.#####"));
    5.     }
    And here's the debug line it gives me when I stop holding the joystick.
    OnMove: (.02975, -.03459) ----> Non-zeroed.
     
  5. foshe_5

    foshe_5

    Joined:
    May 9, 2019
    Posts:
    2
    I did the same thing but in the inspector, but the values are fixed, meaning when I press A I get an output of (-1) and (1) if i press D, i want it to gradually go back to zero, how to do that ?
     
    Bencarbon likes this.
  6. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,387
    There's no support for this ATM. Stateful processors are on the list for >1.0.

    What gamepad are you using? When letting go of the stick, the value should go back to (0,0). If it doesn't, that would be a bug. What value are you seeing in the input debugger?
     
    foshe_5 and SomeGuy22 like this.
  7. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    865
    I'm using an XBOX controller and what I see in the input debugger is the line here:

    I looked at one of your demos in the projects available (in the PackageManager) and I saw that you guys checked to see if the value was too low like in the code below to avoid that issue.

    Code (CSharp):
    1.     public void OnMove(InputAction.CallbackContext context)
    2.     {
    3.         MoveAxis = context.ReadValue<Vector2>();
    4.         if (MoveAxis.sqrMagnitude < 0.01f)
    5.             MoveAxis = Vector2.zero;
    6.     }

    In the standard input system there's a "Dead" value. This might be the reason why it's different from your new input system.
    upload_2019-10-10_17-39-8.png
     
  8. gamefish

    gamefish

    Joined:
    Jul 5, 2013
    Posts:
    11
    I got my Input.GetAxis("Horizontal") working by using 1D Axis, just click the plus button and add 1D Axis Composit, hope this helps:
    Screen Shot 2019-10-21 at 7.50.17 PM.png
     
  9. camposcreativestudios

    camposcreativestudios

    Joined:
    Jun 2, 2020
    Posts:
    2
    Is there any update on dampening the input value? I'm currently using v 1.0.
     
  10. Balaa

    Balaa

    Joined:
    May 3, 2016
    Posts:
    1
    Hey, i find a solution for this. If anyone is still looking for. Basically if you put your "inputSystem.movement.ReadValue<x>()" inside "Awake()" or "Start()" you will actually invoke the callback just one time when the system detects the input and never updating that value until it comes back to "input.movement.cancelled" and the player make another move so, the solution is to put your "input.movement.ReadValue<x>()" in Update(). Then everytime it updates it will get the current updated value of the input.
     
  11. FileThirteen

    FileThirteen

    Joined:
    Oct 23, 2012
    Posts:
    8
    Alternatively could you tell us the math equation that is used in the old Input Manager that takes sensitivity and gravity into account?
     
  12. KUNGERMOoN

    KUNGERMOoN

    Joined:
    Apr 29, 2020
    Posts:
    2
  13. kris8360

    kris8360

    Joined:
    Jan 11, 2013
    Posts:
    23
    Hi, I have the same problem too, I managed to change every other input in my game to the new input system, except for the movement Input.GetAxis Horizontal/Vertical. Did you manage to find a solution?

    My main problem is, that all I get is digital input with the WASD keys, even if I set the control type to Analog.
    With the old GetAxis, I got a smooth acceleration, it took a couple of frames to go from 0 to 1. Now its instant, and when I run in circles it looks stupid.

    Even with a PS4 controller's analog stick, the old Input.GetAxis is a 1000 times smoother, when I run around in circles with the new input system it's really choppy. (update mode set to Dynamic Update)
     
unityunity