Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

New input system axis just gives 0 or 1, instead of intermediate values as in old getAxis()

Discussion in 'Scripting' started by KokodokoGames, Jul 21, 2020.

  1. KokodokoGames

    KokodokoGames

    Joined:
    May 20, 2014
    Posts:
    40
    I'm trying to learn the new InputSystem. I have made a control for speeding / braking with the up / down arrow keys. I made a "driving" map with key bindings for the up and down arrow keys.

    This works! But the problem is, these key presses now only return -1, 0 or 1.
    With the old input system and `getAxis()` you would get a smooth transition that slowly goes back from 1 to 0 instead of being either 0 or 1.

    Even setting the action to "value" and "axis" has no effect, see screenshot.



    How can I get smooth transitions in the new inputSystem?
     
    curiosissimo likes this.
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    The new input system doesn't have support for this yet. It's apparently on the roadmap for future versions of the module.

    Basing my info on this post: https://forum.unity.com/threads/how...-in-the-new-input-system.706562/#post-5051681

    I know you can write your own custom Input processor https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Processors.html but I've never done that and I'm not sure what one would look like that does what you want.

    You'll have to do it yourself in your script, or go back to the old input system.
     
    KokodokoGames and Joe-Censored like this.
  3. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    685
    Try using Mathf.Lerp() to smooth things.
     
    KokodokoGames likes this.
  4. KokodokoGames

    KokodokoGames

    Joined:
    May 20, 2014
    Posts:
    40
    Thanks for the hint, I found this lerp solution using MoveTowards:

    Code (CSharp):
    1. float inputValue = controls.Driving.Speed.ReadValue<float>();
    2. currentValue = Mathf.MoveTowards(inputValue, currentValue, 0.25f * Time.deltaTime);
    3. transform.Translate(Vector3.forward * Time.deltaTime * currentValue * speed);
    My only question is, do I need Time*deltaTime twice here?
     
    Last edited: Jul 26, 2020
  5. cesarbmath

    cesarbmath

    Joined:
    Jan 28, 2022
    Posts:
    1
    Excelent... Thanks
    Code (CSharp):
    1. Vector2 currentMovement = movement;
    2. movement = movementControl.action.ReadValue<Vector2>();
    3.  
    4. movement.x = Mathf.MoveTowards(currentMovement.x, movement.x, 5f * Time.deltaTime);
    5. movement.y = Mathf.MoveTowards(currentMovement.y, movement.y, 5f * Time.deltaTime);
    6. .
    7. .
    8. .
    9.  
     
  6. MaoGee

    MaoGee

    Joined:
    May 22, 2022
    Posts:
    1
    what is movementControl here