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 (i.e.it'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:
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
Gamepad Left X Axis >30 : call JumpFunction
On FireFunction : Spawn bullet
On JumpFunction : Player simulate jump
Develop games in your browser. Powerful, performant & highly capable.
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.