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

event “performed” in Input System 1.1.0-preview3 sounds like it can be what you are seeking.

Enum InputActionType | Input System | 1.1.1 and Class InputAction | Input System | 1.1.1 sound like “peformed” occurs only on change ie. 0 → 1 (or 0 → 0.01 → 0.02 …) and not 1 → 1.

Class InputAction | Input System | 1.1.1 might help then

I have just tested this, using the latest preview version of the new input system.

And unfortunately, I only get “changes” when I get the “performed” callback. So as soon as I have moved the joystick all the way to one side, then I get no more “performed” callbacks until I move the joystick again.

@Rene-Damm Is this working as designed or a bug? If this is the design, how would I get joystick moved callback every frame?

I don’t know if people are still struggling with this … but I was. Here’s how I solved basic WASD character movement.

and then processed with the following code…

private void Awake()
    {
        input = new PlayerInput();

        input.CharacterControls.Movement.performed += ctx =>
        {
            var v2 = ctx.ReadValue<Vector2>();
            movement = new Vector3(v2.x, 0,v2.y);
        };
    }

    void Update()
    {
        transform.Translate(movement * Time.deltaTime);
    }

In the input ‘interactions’ it’s important to use ‘Press and Release’ so the ‘zero’ vector will be recorded and the player will stop moving.

If you want to simple read the value at any point you can do so by finding the action and invoking a read directly. You don’t have to wait for an event. In the example below it gets the action at start and reads on every update.

        public string actionName = "SomeAction";
        private InputAction action;

        private void Awake()
        {
            playerInput = GetComponent<PlayerInput>();
            action = playerInput.actions.FindAction(actionName);
        }

        private void Update()
        {
            Debug.Log("Action Value: " + action.ReadValue<float>());
        }

Hey, I know it’s been a while but, if anyone needs a quick way of doing this with a gamepad as well, here’s what I did:

Vector2 leftJoystickInput = Gamepad.current.leftStick.ReadValue();

horizontalInput = leftJoystickInput.x; //You can use this float to act like Input.GetAxis("Horizontal")

There’s a couple of ways you could improve on it, but that should get it

I think this is it:

    float currentValue;
    int lastDirection;

    float sensitivity = 3f, gravity = 3f;
    bool snap = true, invert = false;

    InputActionAsset actions;
    string horizontalAxis = "Horizontal";

    private void Update() {
        float targetValue = actions[horizontalAxis].ReadValue<float>();

        if (invert) {
            targetValue *= -1f;
        }

        if (Mathf.Approximately(targetValue, 0f)) {
            currentValue = Mathf.MoveTowards(currentValue, targetValue, Time.deltaTime * gravity);
        } else {
            if (snap) {
                int currentDirection = Mathf.RoundToInt(Mathf.Sign(targetValue));

                if (currentDirection != 0 && lastDirection != 0 && currentDirection != lastDirection) {
                    currentValue = 0f;
                } else {
                    currentValue = Mathf.MoveTowards(currentValue, targetValue, Time.deltaTime * sensitivity);
                }

                lastDirection = currentDirection;
            } else {
                currentValue = Mathf.MoveTowards(currentValue, targetValue, Time.deltaTime * sensitivity);
            }
            //From here current value should be equal to Input.GetAxis()
        }
    }

There’s obviously much better ways to access the value so using the inputActionAsset this way is just an example, you can use whichever new input system mechanism you want to get the input, but for the damping this is how you get it.