And here is my last problem:
- the first 2 states of my combo attack deal absolutely no damage, and the third one outputs only a damage value of 10 (I had to turn off the enemy’s weapon box collider to see this work), regardless of what value I throw into it… This was a past value, and now it deals absolutely no damage
(Before we start, to be able to get this kind of data, I had to either slow my enemy’s attack animation speed down to an absolute zero, or turn his weapon’s Box Collider (or it’s trigger) off)
So for this one, to keep this as simple and direct as possible, my first 2 strikes of the combo attack play the animations perfectly fine, BUT… they deal absolutely no damage, and the third animation hits a weird value of 10 (why is it weird? Because there’s literally no numerical number of 10 in any of my state indexes in my latest update, not in knockbacks, force receivers, impulses or any other values… as you can see in the screenshot below):
I’ll attach my ‘PlayerAttackingState.cs’ script below, as I believe it is potentially responsible for the error below:
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.Weapon.SetAttack(attack.Damage, attack.Knockback);
// stateMachine.Shield.SetAttack(attack.Damage);
stateMachine.Animator.CrossFadeInFixedTime(attack.AnimationName, attack.TransitionDuration);
}
public override void Tick(float deltaTime)
{
Move(deltaTime);
FaceTarget();
// guard to stop us from accidentally getting data from the last animation frame:
float normalizedTime = GetNormalizedTime(stateMachine.Animator, "Attack");
if (normalizedTime >= previousFrameTime && normalizedTime < 1f) {
// if (normalizedTime < 1f) {
if (normalizedTime >= attack.ForceTime) TryApplyForce();
if (stateMachine.InputReader.IsAttacking) {
TryComboAttack(normalizedTime);
}
}
// if the player isn't holding down the mouse, return to whatever state he was previously in:
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 we don't have a combo, or just finished the last one (ComboStateIndex = -1), return:
if (attack.ComboStateIndex == -1) return;
// if we are not ready to combo attack, return
if (normalizedTime < attack.ComboAttackTime) {
return;
}
// Do the combo attack:
stateMachine.SwitchState (
new PlayerAttackingState(
stateMachine,
attack.ComboStateIndex
)
);
}
private void TryApplyForce() {
if (alreadyAppliedForce) return;
stateMachine.ForceReceiver.AddForce(stateMachine.transform.forward * attack.Force);
alreadyAppliedForce = true;
}
}