Enemy not always facing the Player

Just discover that I can sneak around the enemy and he’s still striking where I stood initially.
Untitled video - Made with Clipchamp

The solution is to move the FacePlayer() method to the top of Tick method in EnemyChasingState, and all works well again

public override void Tick(float deltaTime)
    {
        FacePlayer();

        if (!IsInChaseRange())
        {
            stateMachine.SwitchState(new EnemyIdleState(stateMachine));
            return;
        }
        else if (IsInAttackRange())
        {
            stateMachine.SwitchState(new EnemyAttackingState(stateMachine));
            return;
        }

        MoveToPlayer(deltaTime);

        stateMachine.Animator.SetFloat(SpeedHash, 1f, AnimatorDampTime, deltaTime);
    }

Untitled video - Made with Clipchamp (1)
Now he does the right thing rather than slashing into nothingness.

1 Like

Privacy & Terms