at the moment the player can punch multiple times a second i want to slow that down so the player has to time their punches rather than spamming the attack button
Welcome!
I dont know if you’re having problems with inputs (like holding and not pressing) but this can help: https://defold.com/manuals/input/
About fighting games. Each move like a punch or kick have a number of frames and during that time you can’t perform any other action. 1 second = 60 frames. Example:
This kick is 32 frames (total). But a punch (like you used as example) have a lower number of frames. Street Fighter has a lot of 3 frames punches. Super fast. But they changing it on hit, on block (recovery).
I hope this helped.
Hello!
I made a fighting game in Defold earlier this year, though I just threw it together to occupy myself while bored at works during the first COVID lockdown, so the code is not exactly clean, plus I took some shortcuts, such as hit recovery being decided by in-game physics (so kinda random).
The source is here, if you want to check it out. Input is handled in the on_input() function here and the function execute_move() right above it. Pretty much all the special moves are hardcoded to some extent, so there’s a lot of ballast you’ll have to ignore if you want to make any sense of it.
Edit: I completely forgot - all the moves are stored in this lua module. “damage_point” is how many frames after making the move the hitbox appears and can damage the opponent, “recovery” is the number of frames until the player making the move is allowed to do anything else. So these would correspond to the red “active frames” part of the picture alex.almeida posted, though note that for most attacks in my game there’s only one frame where damage can be dealt (so the opponent cannot run into your fist and get damaged that way). There’s loads of exceptions to this, such as flying attacks (the hitbox is active until the attacking player touches ground in that case).
Henlo and welcome~
What I would be doing in your situation would try to do something with variables. Have like a variable declared earlier in the script set to your cooldown number in frames. Have another variable that has to do with the attack state, set to false. When this state is set to true, the other variable is set to count down in an if-then statement checking to see if the attack state is true. When this timer goes down to zero, you can have the button be pressed again.
I don’t know if this is useful or not, I’m sorry if it didn’t help at all.
This sounds like Lua code running every frame. I would try to avoid that and go for a more reactive approach:
Use a variable to track if the player is attacking or not.
When a key or key combo is pressed you check if the player is already attacking.
If true then ignore the attack.
If false play the attack animation and set the variable to true.
When the animation has finished (callback from sprite.play_flipbook) you clear the variable.
You can optionally also start a timer and instead clear the variable when the timer triggers. That way you can allow for a new attack recent if the current animation hasn’t finished.
thanks that solved another problem i had too
thank you
thank s
cheers