Hi, When I try to do all 3 combo’s I get this error in the console
and my attacks is setup as follows:
my code in PlayerAttackingState.cs is as follows
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, 0.1f);
}
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.ComboAttackTime == -1 ) { return; }
if (normalizedTime < attack.ComboAttackTime) { return; }
stateMachine.SwitchState
(
new PlayerAttackingState
(
stateMachine,
attack.ComboStateIndex
)
);
}
private void TryApplyForce()
{
if (alreadyAppliedForce) { return; }
stateMachine.ForceReceiver.AddForce(stateMachine.transform.forward * attack.Force);
alreadyAppliedForce = true;
}
private float GetNormalizedTime()
{
AnimatorStateInfo currentInfo = stateMachine.Animator.GetCurrentAnimatorStateInfo(0);
AnimatorStateInfo nextInfo = stateMachine.Animator.GetNextAnimatorStateInfo(0);
if(stateMachine.Animator.IsInTransition(0) && nextInfo.IsTag("Attack"))
{
return nextInfo.normalizedTime;
}
else if (!stateMachine.Animator.IsInTransition(0) && currentInfo.IsTag("Attack"))
{
return currentInfo.normalizedTime;
}
else
{
return 0f;
}
}
}
can anyone see what is causing this, and what I’ve overlooked, cause as I can see I’ve followed how the lecture code is