0 votes

I am working on a 2D action platformer. When is_action_just_pressed("attack"), my player enters attack_state1. If the user presses the button again within a window, the player enters attack_state2, and so on. This is how I achieve attack combos.

I am thinking about overloading the button so that, if held, the player enters heavy_attack_state and performs a heavy attack.

My question concerns the best way to overload the button so that it can recognize when a heavy attack is being performed (when the button is held), but still feel responsive enough when quickly tapped to do the quick attacks?

I tried using is_action_just_released() to trigger the quick attacks, but it doesn't feel good, especially since the player is likely to hold the button down when they press it for the final attack in a combo.

Any ideas about how to overload the button in a satisfying way?

in Engine by (1,548 points)

2 Answers

+1 vote
Best answer

You've got a few options that I can think of.

The first idea is to listen for the initial press, then start counting time, and decide what attack to execute when the button is released, based on how long it was held down. This lets you tell the difference between a quick attack and a heavy attack pretty cleanly. However, this also means that the action is decided on the button release, which might feel a bit sluggish depending on the game (and the players).

Another option would be to start the fast attack as soon as the button is pressed, but then cancel it and switch to a heavy attack if the button is held down for a certain amount of time. This avoids the possibility of players feeling lag, but it does mean the fast attacks have to be able to deal with possibly being canceled. It might be a bit awkward if you're activating hitboxes for the fast attack immediately and then deactivating them when it turns out to be a heavy attack.

by (629 points)
selected by
+1 vote

You can make first fast attack active on release, so that way you can handle hold time. If player holds button for longer then it's heavy attack (that way you can make attack hit harder if it's held for longer), if not then do first quick and follow that with next fast attack but on press rather than release, before that check if previous attack was fast. To avoid attacks after first fast to be heavy AND fast at the same time, allow heavy attacks to be executed once in a while rather than spam (like 20ms), refresh that duration every time player executes fast attack different than first. Just my thoughts, hope that helps a little.

by (379 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.