How do I make a 3 hit combo?

I’m trying to impliment a 3 hit combo into my game but I can’t seem to figure it out. I know the reason for this is because my code isn’t counting the variables correctly, but I don’t know how to fix this. (I’ve been following multiple guides so there is a change the code is conflicting with itself)

My code for attacks:

func _process(delta):
if Input.is_action_just_pressed(“Attack”) and current_punches == 0:
attack()
if Input.is_action_just_pressed(“Attack”) and current_punches == 1:
attack2()

func attack():
var overlapping_objects = $HitBox.get_overlapping_areas()
for area in overlapping_objects:
var parent = area.get_parent()
parent.queue_free()
attacking = true
if Input.is_action_just_pressed(“Attack”) and is_on_floor():
animation.play(“punch”)
cant_move = true
current_punches+=1
print(current_punches)
else:
animation.play(“airkick”)

func attack2():
var overlapping_objects = $HitBox.get_overlapping_areas()
for area in overlapping_objects:
var parent = area.get_parent()
parent.queue_free()
attacking = true
if Input.is_action_just_pressed(“Attack”) and is_on_floor():
animation.play(“punch2”)
cant_move = true
current_punches+=1
print(current_punches)
else:
current_punches = 0

Heyo!

You could probably have a punch function called by your input_button pressed under your func _ process(). Then let your combo conditions be under the punch function and have a timer to allow for time between punches.

Func punch() -> void:
     Combo += 1
     If combo == 1:
           Punch1
           Combo_timeout_timer.start
     If combo == 2:
           Punch 2
           Combo_timeout_timer.start
#(As many punches as you want)

Func combo_timeout_timer()
         Combo = 0
           
     

I hope this helps!

3 Likes

Oh also, in your code, your checking for if Input.is_action_just_pressed(“Attack”) twice. Once in the process and once in the functions. This is probably causing some issues. Are your animations and prints playing? I would think that the button press condition wouldn’t track. Also you shouldn’t need to check for a button press already since you did in the process func.

2 Likes