How do I create an 8 directional input system with a controller joystick?

0 favourites
  • 4 posts
From the Asset Store
Small pixel icons for the 3 most popular controller types.
  • I am trying to make an input sequence similar to the combos used in fighting games. However, whenever I input using the joystick on my controller, it doesn't input the way I'd like. For example, if I tilt my joystick upright, I would like it to input it as "upright" but instead it thinks "up" and "right" as if it was two inputs.

    Here's the code I have so far:

    Also, "ControllerDeadzone" is a local variable. Its set to 50.

    Thank you in advance.

  • Why do you need all 8 directions? You can only detect left/right/up/down and the behavior will do the rest.

    Lefx X axis<deadzone : 8direction simulate pressing Left
    Lefx X axis>deadzone : 8direction simulate pressing Right
    Lefx Y axis<deadzone : 8direction simulate pressing Up
    Lefx Y axis>deadzone : 8direction simulate pressing Down
    

    Another option is to calculate the angle:

    Set a to angle(0,0, Gamepad.Axis(0,0), Gamepad.Axis(0,1))

    Then round it to the nearest 45 degrees:

    Set a round(((a+360)%360)/45)*45

    a will contain a number between 0 to 360 in 45 degree increments. For example a=135 means Down+Left.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sorry for the late reply. The second method you gave me is just what I needed. I just have one small problem. If the variable is set to less than 22.5, it rounds down to 0. I would prefer if it would round it to 360 instead.

    Here's what I made.

  • You can add another event: If ControllerAxis=0 -> Set ControllerAxis to 360

    Or with a single action:

    Set ControllerAxis to (ControllerAxis=0 ? 360 : ControllerAxis)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)