When I click the attack button is it supposed to fully play the first attack animation? At the moment it stutters and plays the first few frames of the animation and then returns. It only fully plays when I hold down the attack input.
public class PlayerAttackingState : PlayerBaseState
{
private float previousFrameTime;
private bool alreadyAppliedForce;
private Attack attack;
public PlayerAttackingState(PlayerStateMachine stateMachine, int attackIndex) : base(stateMachine)
{
attack = stateMachine.Attacks[attackIndex];
}
public override void Enter()
{
stateMachine.Animator.CrossFadeInFixedTime(attack.AnimationName, attack.TransitionDuration);
}
public override void Tick(float deltaTime)
{
Move(deltaTime);
FaceTarget();
float normalizedTime = GetNormalizedTime();
if (normalizedTime >= previousFrameTime && normalizedTime < 1f)
{
if (normalizedTime >= attack.ForceTime)
{
TryApplyForce();
}
if (stateMachine.InputReader.isAttacking)
{
TryComboAttack(normalizedTime);
}
else
{
if (stateMachine.Targeter.CurrentTarget != null)
{
stateMachine.SwitchState(new PlayerTargetingState(stateMachine));
}
else
{
stateMachine.SwitchState(new PlayerFreeLookState(stateMachine));
}
}
}
previousFrameTime = normalizedTime;
}
public override void Exit()
{
}
private void TryComboAttack(float normalizedTime)
{
if(attack.ComboStateIndex == -1) {return;}
if(normalizedTime < attack.ComboAttackTime) {return;}
stateMachine.SwitchState
(
new PlayerAttackingState(stateMachine, attack.ComboStateIndex)
);
}