#Is there a gamepad axis equivalent of keyboard_check_pressed?

1 messages · Page 1 of 1 (latest)

still umbra
#

Trying to add gamepad axis support for movement, but i run into trouble when I want it to function like keyboard_check_pressed.

I currently use a function like gamepad_axis_value(0, gp_axislv) < -0.4 to check if the stick is being held or released, but how would I be able to check for it only once like keyboard_check_pressed? Since what the gamepad axis function does is constantly trigger the condition, which is not what I would like for it to do. Would this require a more advanced solution, or is there a simple fix to it?

hoary cipher
#

solution is you need to store an extra frame of those checks

#

and compare your check with previous frame

#

i'd also suggest to have a deadzone of around 0.5 for those checks

#

if for example you want to press left

#

and you've pushed stick to the left past -0.5

#

you trigger your stickpressedleft

#

but only if in previous frame check left was "less" than -0.5

#

like -0.4

#

if in previous frame leftstickcheck was -0.5 or greater like -1

#

that shouldn't trigger pressed

#

so it only should trigger once once you pass the threshold of your deadzone

meager mountain
#

Or, use something someone already made.

still umbra
#

ooh this looks pretty beefy ill take my time to read through this thank u very much

hoary cipher
#

here's what i use

#
    last_p1_AxisV         = p1_AxisV;
    p1_AxisH              = gamepad_axis_value(0, gp_axislh);
    p1_AxisV              = gamepad_axis_value(0, gp_axislv);
    var StickUp           = p1_AxisV < -0.5 ? true : false;
    var StickDown         = p1_AxisV >  0.5 ? true : false;
    var StickLeft         = p1_AxisH < -0.5 ? true : false;
    var StickRight        = p1_AxisH >  0.5 ? true : false;
    var StickUpPressed    = p1_AxisV < -0.5 && last_p1_AxisV > -0.5 ? true : false;
    var StickDownPressed  = p1_AxisV >  0.5 && last_p1_AxisV <  0.5 ? true : false;
    var StickLeftPressed  = p1_AxisH < -0.5 && last_p1_AxisH > -0.5 ? true : false;
    var StickRightPressed = p1_AxisH >  0.5 && last_p1_AxisH <  0.5 ? true : false;```
#

0.5 being my deadzone

#

you can see at the top i'm storing previous frame, before checking current