Adding a platformer dash that works without moving

Godot Version

Version 4


I currently am using a direction variable with get.axis(“left”, “right”) for my player movement in my platformer game, this makes it so the direction value is zero when you are not pressing any keys. I am trying to add a horizontal dash that multiplies a new speed to the direction variable. This makes it so only the dash works while you are walking. Is there a movement script that makes it so the direction variable always has a value and only uses it to move while you are pressing the left and right keys?

A design question arises.

If you press the dash button which way do you want the player to go?

I assume it would be whichever way the character is looking I suppose, so you will need to query which way the character is looking to find the last direction input. Or just keep track of which key was last pressed.

Then you take the direction 1 or -1 times it by the speed. And replace current velocity with the dash velocity. And also while walking just replacing the walking velocity with the dash velocity. I.e the dash velocity should override any movement, maybe even gravity?

I want it wherever the player is facing, but I tried replacing the get.axis() with input.is_action_pressed for each left and right keys. I used this to have direction always have the value, but it made the game never load for some reason. I am already using the dash velocity instead of the normal velocity and it’s not really doing anything. Am I possibly doing something wrong?

I would assume so. Conceptually it is simple, and we have all seen real world examples.

You can post your movement logic and I can take a look. You can get a code block if you put two “```” lines and the code in between. Tabs don’t really work so you may need to space the indentations manual, I typically just do two spaces for each indentation level. Or you can take snapshots using window+shift+s.

1 Like

Also, the dash goes further when you let go of the left and right keys, and you can move in the middle of the dash. I have two timers for the dash, its just not in the screenshot.