Before you proceed, I would recommend reading about state management or state machine / state design pattern. Because fighting game is very complex, I just gave you very simple example.
think that one of player hit the punch button consecutively
that's why you need is_punching
variable. I just realized that can_punch
would be a better name :) or even both: is_punching
for STATE and can_punch
for cooldown. While is_punching == true
your character is in PUNCH STATE, during that time you check for damage/collision, if can_punch == false
, nothing happens when player hit punch key consecutively.
i dont want when i hold punch button, player punch after specific time
that's why you need a timer. It's a COOLDOWN timer.
here is my updated example:
is_punching = false # state of your character
can_punch = true
func _process(delta):
if can_punch && Input.is_key_pressed(PUNCH_KEY):
can_punch = false
is_punching = true
# start COOLDOWN timer
#...
if is_punching:
# check collision / damage
func _on_Animation_finished(anim):
is_punching = false
func _on_Timer_timeout():
can_punch = true
i hope it helps.