• 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!

GameMaker double tap for dash/run, where to put in state engine

P

Palocles

Guest
I'm implementing a State Engine for my game and I'm wondering how double tapping a button for a dash move, at higher speed than a walk, will interact with the state engine.

When the 'forwards' button is pressed the machine puts the player into the walk state but if i release the button, required for a double tap, the machine puts the player back into idle state. So how can I keep the player in the walk state until the second tap is made and changes the state to run? An alarm before it changes state back?

I thought I might have had a similar issue with double jump but with the code in the jump state and the release of the jump key not going to change the state immediately I don't think it will be a problem. But maybe I'll have an issue with coyote time or jump buffering?

Thanks.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I would generally use a variable and an alarm for something like this. So, when the user first taps the move button it would set the "dash" variable to 1, and also set an alarm to something like 10 frames. In the alarm the dash variable is set to 0 again. So, while dash is >0 the player is moving, and if they press the dash button twice you can check to see if the dash variable is 1, in which case dash, or 2 in which case do nothing as they are dashing, or if it is 0, just start them moving as normal.

Hope that makes sense!!!
 

TheouAegis

Member
Don't go immediately back to the idle state when the key is released. Do you have friction or some sort of acceleration and deceleration getting applied to your movement? If so, you can wait until you stop moving before going back to the idle state.
 
P

Palocles

Guest
Thanks Nocturne. I think I've found an example of code like you're talking about so that should, hopefully, not be a problem.

Where I see the potential trouble is with what TheouAegis is talking about; "Don't go immediately back to idle'.

Between this and other State Engine effects I wish I could do that so easily. Some of my states aren't reverting at all and I've yet to determine why.

I'm not using friction but I suppose I can start the timer when the first 'dash' is pressed and have it revert to Idle after the timer if the button is released and not pressed again in the mean time.

It's nearly bed time here but I'm not sure if sleeping on it will help much so any further advice is welcome. I have listed some of my state code in another thread.
 
Top