How do I map the movement of a gamepad axis to a button?

0 favourites
  • 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I want to have the axis of the left gamepad joystick mapped to another button on the controller (unique scenario for a game that will only be played in one place).

    i.e. when I press left on the analogue left thumbstick, this would be the same as a digital press of left POV or another button on the gamepad.

    I can't do 'if left axis is more than' OR 'button X pressed' because I have a redefine keys system that only takes numbers that relate to the button number pressed ('s a digital system).

    So I want 'if left thumbstick axis > 30, then simulate pressing button LB', for example.

    Not immediately apparent. Is there a workaround that I've missed? Or do I need to use an external program (AutoHotKey, vJoy, Joystick Gremlin etc.) to do this?

  • I imagine you map the buttons using a bunch of variables? For example:

    Set JUMP_BUTTON=10

    And you probably have events like these:

    Gamepad On button index FIRE_BUTTON pressed : Spawn bullet
    Gamepad On button index JUMP_BUTTON pressed : Player simulate jump

    You can move these actions into functions and then you will be able to call these functions when either a button or a stick is pressed:

    Gamepad On button index FIRE_BUTTON pressed : call FireFunction
    Gamepad On button index JUMP_BUTTON pressed : call JumpFunction
    Gamepad Left X Axis <-30 : call FireFunction
    Trigger once
    Gamepad Left X Axis >30 : call JumpFunction
    Trigger once
    On FireFunction : Spawn bullet
    On JumpFunction : Player simulate jump
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • YOu're 100% correct in your assumptions. That's what I've got.

    I think your solution works well for trigger events (e.g. jump, shoot), where it would be an action for the first frame only. I think it may not be the way for 'continuous' actions (e.g. moving left/whilst (x) key is down..).

    It's those continuous actions which are the problem! I need a 'if I push the left axis up then simulate pressing the up key!'.

    Might just have to be a less elegant but more expedient code addition operation...

    However, I wonder how people modularise or design this type of thing for multiple control schemes where continuous button presses need to be accounted for. 'Whilst (x) is held down...then...', etc. Would functions be okay for that?

    LATER EDIT: Went away and did what you said - does work, included for 'continuous' direction events.

    I've made an example for anyone else that has this problem in the future:

    (explanation: Made a game on my desktop, but was to go on an arcade machine. Turns out that the joystick in arcade machine was mapped to gamepad axis and not POV/hat cardinals - hence the question. Since I've got state machines for movement in there and all sorts didn't fancy rewriting all the code that had taken me AGES to re-write, so I've kind of 'hacked' in the axis controls on top. But next time - winners use functions people!)

    Thanks to dop2000! Never thought about using functions for movement.

  • Yeah, for continuous actions you can remove "Trigger once" for "Compare axis", and you need to use "Is button down" events for gamepad buttons.

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