I got an attack script for my player that has a bunch of attacks in it, including a simple, three-hit attack chain. Looks a bit like this:
extends State
var currentAttack = null;
func enter(msg := {}) -> void:
owner.isAttacking = true;
if msg.has("standing_light"):
currentAttack = ("Light1");
if msg.has("standing_heavy"):
currentAttack = ("Heavy1");
func physics_update(delta: float) -> void:
owner.velocity.x = 0;
if currentAttack == ("Light1"):
owner.animState.travel("AttackLight1");
if Input.is_action_just_pressed("light_attack"):
if currentAttack == ("Light1"):
owner.animState.travel("AttackLight2");
currentAttack = ("Light2");
else:
owner.animState.travel("AttackLight3");
currentAttack = ("Light3");
if currentAttack == ("Heavy1"):
owner.animState.travel("AttackHeavy1");
if Input.is_action_just_pressed("heavy_attack") and currentAttack == ("Heavy1"):
owner.animState.travel("AttackHeavy2");
currentAttack = ("Heavy2");
For some context, the player script has an 'isAttacking' bool that gets set to true when the state becomes active and each attack changes what the 'currentAttack' value is (this is supposed to help with combos and allow me to see exactly which attack is currently active for debugging). Everything seems to work fine so far save for one problem I'm having: if the light attack button is pressed during any attack that's not part of the light combo, the 'currentAttack' value gets switched to 'Light3.' The attack that was playing plays through and the attack state ends like normal, but then as soon as the player goes back to their original state, the 'Light1' attack plays, which it shouldn't be doing, and since they're no longer in the attack state, that allows them to move and jump around and whatnot while the attack is playing.
I'm pretty sure it has to do with how the light combo chain is organized, but whenever I try to move the other attacks around, it messes up something. I've tried doing a nested if statement and giving each attack its own if statement, but both of these completely skip over the second attack, and a few other methods I've tried wouldn't allow the chain to go past the first attack. None of this happens with the heavy attack combo above either, it's just the light combo chain.
I'm at a bit of a loss on how to fix this, so any insight is appreciated! I know this might have been a little hard to explain, so if anything needs to be clarified or needs more info, let me know.