Hello all
as i am going over my bugs wanted maybe to know how would you Handle the combos with different attacks
by clicking the mouse button to each combo to change
here is how i did it
it sometimes play the first attack twice so im trying to see how i can use the normalizeTime to use it better
public class PlayerAttackState : PlayerBaseState
{
bool isLightAttackPressed = false;
bool isHeavyAttackPressed = false;
int attackIndex = 0;
public PlayerAttackState(PlayerStateMachine stateMachine, int attackIndex) : base(stateMachine)
{
this.attackIndex = attackIndex;
}
public override void Enter()
{
stateMachine.inputHandler.lightAttackEvent += OnLightAttack;
stateMachine.inputHandler.heavyAttackEvent += OnHeavyAttack;
stateMachine.fighter.HandleAttack(attackIndex);
//movement.KnockBack();
}
public override void Exit()
{
stateMachine.inputHandler.lightAttackEvent -= OnLightAttack;
stateMachine.inputHandler.heavyAttackEvent -= OnHeavyAttack;
}
public override void Executue(float deltaTime)
{
if (stateMachine.animatorHandler.isInteracting) return;
if (!stateMachine.fighter.isInCombo && (isHeavyAttackPressed || isLightAttackPressed))
{
HandleCombo();
}
else
{
ReturnToLocomotion();
}
}
private void HandleCombo()
{
HandleLightAttack();
HandleHeavyAttack();
}
private void HandleLightAttack()
{
if (isLightAttackPressed)
{
//isLightAttackPressed = false;
if (attackIndex > 1)
{
stateMachine.SwitchState(new PlayerAttackState(stateMachine, 0));
return;
}
stateMachine.SwitchState(new PlayerAttackState(stateMachine, attackIndex + 1));
return;
}
}
private void HandleHeavyAttack()
{
if (isHeavyAttackPressed)
{
//isHeavyAttackPressed = false;
if (attackIndex < 3 || attackIndex > 4)
{
stateMachine.SwitchState(new PlayerAttackState(stateMachine, 3));
return;
}
stateMachine.SwitchState(new PlayerAttackState(stateMachine, attackIndex + 1));
return;
}
}
private void OnHeavyAttack()
{
if (stateMachine.fighter.isInCombo)
{
isHeavyAttackPressed = true;
}
}
private void OnLightAttack()
{
if (stateMachine.fighter.isInCombo)
{
isLightAttackPressed = true;
}
}
}
isInCombo gets updated by an animation event so enable combo in the certain amount of time in the animation to get a click for light attack or heavy attack
then to see if light attack or heavy attack is pressed
and then switch to which attack
Fighter holds all the attacks light attacks and heavy attacks
if you want more info or other suggestions how to handle this let me know