Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to capture D'Pad in the same format as the axis?

Discussion in 'Input System' started by LeoFeitosa, Jul 30, 2020.

  1. LeoFeitosa

    LeoFeitosa

    Joined:
    Jul 5, 2017
    Posts:
    32
    Hi guys
    Would anyone know how to tell me how to capture the values of the DPad so that they are similar to the values coming from the axis?
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Not sure what yo mean by similar values. Both the sticks and the dpad give the same ([-1..1],[-1..1]) values.

    As far as gamepads go, you can read the dpad as a whole which gives a Vector2 just like the stick. Or if you're looking for individual axes, the dpad has an x and y axis like the sticks.

    Code (CSharp):
    1. // Vector2.
    2. Gamepad.current.dpad.ReadValue<Vector2>();
    3. Gamepad.current.leftStick.ReadValue<Vector2>();
    4.  
    5. // X and Y axis.
    6. Gamepad.current.dpad.x.ReadValue<float>();
    7. Gamepad.current.dpad.y.ReadValue<float>();
    8. Gamepad.current.leftStick.x.ReadValue<float>();
    9. Gamepad.current.leftStick.y.ReadValue<float>();
     
    LeoFeitosa likes this.
  3. LeoFeitosa

    LeoFeitosa

    Joined:
    Jul 5, 2017
    Posts:
    32
    @Rene-Damm
    Thank you very much, it worked, but the angles captured by d'pad are only in variations of 45 degrees.
    Is there a way to take all possible degrees to form a circle?
     
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Unfortunately no. Given the dpad is only four buttons, it can't by itself produce more nuanced angles. They can be artificially produced by interpolating between the angles over time but there's no support for this out-of-the-box ATM and it tends to produce sluggish behavior.
     
    LeoFeitosa likes this.