• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Tapping a button repeatedly to dash rather than one press

D

deuschristiamor

Guest
I can set up a character and give him the ability to move faster if I press a certain key. Is there a way to set it up to where I can press that button repeatedly to slowly reach max speed rather than instantly with one single press?
 

YoSniper

Member
I would suggest setting a timer when the key is pressed, and that timer counts down to zero. If the key is pressed again before that timer hits zero, make the player go into the dash.

Then you can disable the dash when the key is released.

For example:

Create Event
Code:
tap_timer = 0;
dash = false;
Key press event
Code:
if tap_timer > 0 {
    dash = true;
}
tap_timer = 10;
End of Step Event
Code:
if tap_timer > 0 {
    tap_timer -= 1;
}
if not keyboard_check(key) {
    dash = false;
}
 
D

deuschristiamor

Guest
I see where you are going. can we take that and slowly increase the speed of the character until it hits a max speed ?
 

hippyman

Member
What you want is a min and max speed. Then have a deceleration variable to slow down the speed when it's higher than the minimum speed. Then every time you press the run key/button, increment the speed value if it's lower than the max value. Then finally apply the current speed to your movement.
 
D

deuschristiamor

Guest
What you want is a min and max speed. Then have a deceleration variable to slow down the speed when it's higher than the minimum speed. Then every time you press the run key/button, increment the speed value if it's lower than the max value. Then finally apply the current speed to your movement.
What would a deceleration variable end up being?
 
D

deuschristiamor

Guest
So right now this is my movement
Code:
xDirection = o_input.right_key - o_input.left_key;
yDirection = o_input.down_key - o_input.up_key;
//movement

x += xDirection * min_speed;
y += yDirection * min_speed;
Now I have to find a way to track multiple taps of the same key and add to the speed then reset back to the minimum speed after a certain window like maybe 1-2 seconds.
 
Top