1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

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

Discussion in 'Programming' started by PepticPaladin, Dec 28, 2018.

  1. PepticPaladin

    PepticPaladin Member

    Joined:
    Nov 10, 2018
    Posts:
    18
    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;
    
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,025
    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.
     
  3. PepticPaladin

    PepticPaladin Member

    Joined:
    Nov 10, 2018
    Posts:
    18
    How would I do this with an analog stick?
     
  4. Relic

    Relic Member

    Joined:
    Jun 27, 2017
    Posts:
    725
    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: Dec 28, 2018

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice