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

Stop Diagonal movement DPad

Discussion in 'Input System' started by noyogiisMYusername, Jul 23, 2020.

  1. noyogiisMYusername

    noyogiisMYusername

    Joined:
    May 18, 2020
    Posts:
    21
    Using the new Input System, is there a way to stop diagonal movement?

    I'm currently using:
    Action Type: Pass Through
    Control Type: Vector 2
    Composite Type: 2D Vector
    Mode: Analog
    Interactions: Hold
    Processors: Normalize Vector 2
    Binding Path: D-Pad/Left (also Down and Right)
    Code (CSharp):
    1. private void OnEnable()
    2. {
    3.     playerControls.Enable();
    4.  
    5.     playerControls.Player.Move.started += Move;
    6.     playerControls.Player.Move.performed += MoveX;
    7.     playerControls.Player.Move.canceled += StopMove;
    8. }
    9.  
    10. private void Move(InputAction.CallbackContext context)
    11. {
    12.     var moveX = context.ReadValue<Vector2>();
    13.     validate.MoveCheck(false, moveX);
    14. }
    15. private void MoveX(InputAction.CallbackContext context)
    16. {
    17.     xIsPressed = true;
    18.     var moveX = context.ReadValue<Vector2>();
    19.     validate.MoveCheck(true, moveX);
    20. }
    21. private void MoveXO(InputAction.CallbackContext context)
    22. {
    23.   xIsPressed = false;
    24. }
    I would like to continue using Vector 2 as Control Type, but have an axis override option;
    pressing right you go right, then when down is triggered in addition to right (this is on xbox D-Pad), right is overridden and the character moves down rather than diagonally.

    I remembered seeing that I could get separate axis readouts from the d-pad, but I can't find that option anymore. With separate axis I can stop diagonal movement with code, but I would like to read one vector 2 rather than 2 axis readouts.

    On another note the listen function for selecting the binding path stopped working, this has happened before, but I think that was due to being in the usage section, I think it was solved before by just pressing a little back arrow to get to the main menu. (I suppose this last part should be posting in the beta section as I am using 2020.1.b16)
    Thank you
     
    Last edited by a moderator: Jul 23, 2020
  2. noyogiisMYusername

    noyogiisMYusername

    Joined:
    May 18, 2020
    Posts:
    21
    The non functioning bind path selector and Listen function were not working because in Project Settings/Input System Package/Supported Devices I had Gamepad and Keyboard selected. I removed all devices from supported devices and the selector returned to its working state.