How to overload an attack button?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Diet Estus

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?

:bust_in_silhouette: Reply From: markopolo

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.

:bust_in_silhouette: Reply From: Oen44

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.