GMS 2 Detecting 2 quick movement inputs for both keyboard and gamepad

P

PepticPaladin

Guest
I wanted to implement a "dash" feature in my game, and I would like to do it by having the player press a movement key twice quickly. I could probably do this rather easily if I ere only using keyboard, but I also want controller support, and I'm having trouble with detecting 2 quick inputs using a joystick.

This is my input code:
Code:
xinput = keyboard_check(vk_right) - keyboard_check(vk_left);
yinput = keyboard_check(vk_up) - keyboard_check(vk_down);

var leftanalogH = abs(gamepad_axis_value(0,gp_axislh));
var leftanalogV = abs(gamepad_axis_value(0,gp_axislv));
if (leftanalogH > 0.2)
{
    xinput = (max(gamepad_axis_value(0,gp_axislh),0) - abs(min(gamepad_axis_value(0,gp_axislh),0)));
    gamepad = true;
}
if (leftanalogV > 0.2)
{
    yinput = -(max(gamepad_axis_value(0,gp_axislv),0) - abs(min(gamepad_axis_value(0,gp_axislv),0)));
    gamepad = true;
}

xmovement = xinput * __accel;
ymovement = yinput * __accel;
 

TheouAegis

Member
Use a timer and keep track of the last key pressed. If the timer is counting down and the samekey was pressed treat it as a double tap; otherwise reset the timer.
 
P

PepticPaladin

Guest
Use a timer and keep track of the last key pressed. If the timer is counting down and the samekey was pressed treat it as a double tap; otherwise reset the timer.
How would I do this with an analog stick?
 

Relic

Member
You will need to store the value from previous steps as there is no key pressed equivalent.

Add some logic like:

Count down a variable called just_pressed_timer each step.
Was analog value below 0.2 last turn and more than 0.2 this turn and just_pressed_tiker is less than 0? Set Just_pressed_timer to 10 (or whatever)

If analog value was less than 0.2 and is now more than 0.2 AND just_pressed_timer is more than 0, activate dash.
 
Last edited:
Top