Combo Attacks


The Problem: Left ho->Right h->Uppe->Left...

One of the major goals for this week was to have a basic combo attack working for the player. This feature is very important to have because we had decided that the combat of our game is going to imitate that of the Dynasty Warriors games. In those games there are hordes of enemies and chaining combo attacks together is what makes their combat fun, so that's what we are trying to achieve with our combat.

So, coming into my approach for this feature, I knew there were a few things I need to implement. I need to have an attack animation play out fully, or as much as I needed it to, before transitioning to the next animation; I needed to "save" the attack input from the player while an attack animation was playing so I can determine whether or not to transition to the next attack in the combo when the current one finished; the last thing I needed to do was reset the combo if the player did not give any input after some time. The main problem I was having with my first few approaches was when the player repeatedly presses the attack button, the current animation that is playing gets "overwritten" with the next one resulting in none of the animations playing out fully.


The Solution: Left hook->Right hook->Uppercut->Hadouken

So, the animations would start but never finish if the player continued to repeatedly press the attack button. A temporary solution I came up with was done with five functions. One that initialized the attack when the attack button is pressed:

if isAttacking is true // if you're already attacking
    saveAttack = true   // "save" the attack for later 
else     
    isAttacking = true // now you are attacking     
    Attack() // so call the attack function

The attack function then played the respective animation based on which attack in the combo you were on which was kept track of with an integer. However, before it did this it would check if any animations were already playing and if any were, it would do nothing. it looked something like this:

if any attack animations are playing     
    return 
else     
    switch (comboCount)     
        case 0:         
            play anim1         
            comboCount = 1     
        case 1:         
            play anim2         
            comboCount = 2     
        case 2:         
            play anim3         
            comboCount = 3     
        case 3:         
            play anim4         
            comboCount = 0

I also had a second function, ComboAttack, bound to the attack button being pressed that looked like this:

if saveAttack is true // if the player is currently attacking     
    saveAttack = false // reset this value     
    Attack() // and try to attack again

Another function called StopAttack would be called when the button was released and would set a timer that when finished would call a ResetCombo function that reset all variables keeping track of the combo, and this timer gets reset every time the button is released to keep the attack going. This system worked but the problem with it is the player would have to constantly press and release the attack button to reset the timer every time they released the button. We don't want our players to have to go out and buy a new mouse or controller after one play session of the game so I had to change this.

What I ended up doing was using two animation-notifies to call functions. The functions were the ComboAttack and ResetCombo functions, and I set the notifies in the animation at points that I was comfortable with transitioning to the next animation and resetting the combo respectively. I also unbound the ComboAttack function from the attack button and completely got rid of the StopAttack function as I did not need it anymore. This allowed for a smooth transition from one animation to another and only makes the player press the attack button a total of four times to do the full combo. This is because during an animation, if the player is already attacking, they would press the attack button and that would "save" the attack if the press occurred before the notify, and when the SaveAttack notify fires towards the end of the animation it will call the ComboAttack function and play the next animation in the combo. Otherwise, if the player did not press the button before the first notify it would then fire the ResetCombo notify to reset the combo.

Get Lucifer's Hordes

Leave a comment

Log in with itch.io to leave a comment.