Skip to content

Attack Manager

Mikhail Albershtein edited this page Apr 5, 2020 · 25 revisions

The attack manager controls attack through animations and movement. There are are two types of attacks: strong and fast. You can mix both attacks to create combos. Let's examine the IAttackManager interface:

IAttackManager

  • Strong/fast attack - a method which is being called from InputManager(Fire1 for the strong attack, Fire2 for the fast attack). First, we have to make sure that we can attack in the current state(we can only attack in GroundMovement or AttackignMovement
  • AddCombo - Adds combo to the current combo amount. This method is being called from Animation attack state when we press the attack button in a combo gap
  • ResetCombo - resets combo to 0. If we didn't press the attack button in time, the combo will be reset. This method is called from the Animation trigger.
  • GetCurrentCombo - returns the current combo amount
  • CreateDamageInfo - create a damage for each attack. It's being created for every animation so we can have different damage amounts for every combo attack.

Combo

ComboSystem

Each attack has to be extremely customizable so that's why I didn't create the generic solution for every attack, although it uses the same classes you should configure every animation by yourself so it will feel the way you want it to feel.
We will use animations of unity closely with code to achieve this effect.

To simplify the animation transitions we use the Sub-State machine. As you can see from every attack animation we can go to the upper level. It happens when we don't press any attack button while the character is in the combo gap. If we do press the attack button in the combo gap we transfer to the next combo attack depending on the attack we pressed(fast or strong)

Add combo

Before we dive into the combo gap let's see have a look at the animation state of each attack. If you didn't check AnimatinoState please have a look at it before continuing.
We are only interested in the enter method. It adds combo to the animator manager and creates the current damage info for the current damage for the attack manager.
Be aware, because this method is being called when the transition starts!!!
transition
combo transition

Reset combo

If we didn't press the button for the attack in a combo gap, the combo is resetting and the state is being changed. When the combo is being reset? Each animation has to have a special trigger - finishTimeForCombo from AnimationStateFacade
reset trigger
Be careful, the transition of the to the next combo attack should end before the reset combo trigger reset trigger
reset trigger


Combo Gap

So after we went through the combo triggers, let's define the combo gap. A combo gap is a moment between the start of the transition of the animation and when the animation has a reset trigger
During this time we can continue the combo

Start of the combo gap

Combo gap start 1
Combo gap start 2

End of the combo gap

End of the combo gap


Dealing damage

So, how does the character deal damage? First, please see Hurtbox and Hitbox before continuing.
The attack manager has currentDamageInfo which is being changed every time the attack animation starts which will be the damage if the character hits something. How do we know when we hit something? In we look into the game object structure we will find hitbox objects

Hitboxes

But they are deactivated. We need to activate them during the animation

Hitbox animation

We can modify the trigger collider(size, offset, so on...) during the animation. Don't forget to disable it at the end.

activated hitbox

When the hitbox registers the hit(more in hitbox) we check if that's a hurtbox. If it is, then we pass hurtbox to the character(IDamageDealer), which is passing it to the attack manager. Attack manager then takes the current damage info and calls the takeDamage with the damage info from the hurtbox that was passed. It seems a little bit complicated but I hope this graph will help you understand the flow:

damage flow

Why do we have to pass hurtbox through character?

The purpose of it was to store and add more logic(for example: calculate all the hits for a specific hurtbox, upgrade character after some amount of hitx, so on...). I decided to keep it here, although it's possible to delete the character layer and pass it directly to the attack manager.