Make the "Dash" go straight

I am working on something similar. I wanted to make a character dash on a double tap (much like MMX) but I don’t have a jump dash.

I did it using a timer to make sure that the button presses are made in quick succession.

It works with this a little further down…

I tried several different ways of doing this over a few days, and this seemed to give me the best performance. One thing I noted is that you want to have your timer condition as high up as possible on the page or performance suffers. When the timer was inside a subevent of those button presses performance got really bad.

To make it works for your game you could just change the condition “character is on floor” to "character is jumping. I also had to have the stop all forces in there twice or the player would just slide on forever.

Another option you might try is something like:

  • condition:
    • when Variable(dash)=true
    • trigger once
  • Action store player.Y() in Variable(dashSteady)

and near the top of the page you could use

  • condition when Variable(dash)=true

  • action: set the position of player to [x coordinate = player.X] and [y coordinate = Variable(dashSteady)]

[edit]
Looking at it, I wonder if that might throw some funny results. It may lock the player into X position also. If so, you could use Set position instead of add force for your dash.

condition: Variable(dash)=true
action: Set position of player to player.X()+1 and Variable(dashSteady)

with another condition somewhere else to change Variable(dash) to false, and some modifications to the player.X()+1 to +5 or +10 or whatever works for what you’re trying to do.

And then get rid of the added force to your dash event.

Interesting code there fitkoh… I started on some code earlier too and realized it’s going to take variables to get it right, although I was experimenting with timers.

atabynho take a look at fitkoh code and it should hopefully give you a much better idea of how to achieve the effect

Thanks for the help! Hope I can make it work!

I messed with things a bit and came up with a few improvements.

This new version doesn’t use any timers. Timers are awesome programming tools, but once you get a few different timers going, it can cause lag problems.

Instead of timers, I use the frame rate to keep track of timing.

Under the assumption that most gdevelop games run at ~60fps, you just set a counter and when it gets to 60 you can assume that’s about a second. Removing all the timers made a noticeable difference in how smooth the game runs - not a monumental difference, but noticeable.

This version, for me, works exactly how I want it to.

I changed the apply force to set position. For some reason, if the player dashed twice in a row quickly, it added the first force to the second force, even when there was a stop all forces in between. Since I’m not adding any force to the player, I don’t have to worry about stopping any forces.