Beispiel #1
0
        private void InitActionStateMachine(NavMeshAgent navMeshAgent, Animator animator, TargetDetector <PlayerController> playerDetector)
        {
            _actionStateMachine = new AIStateMachine();

            Fighter fighter = new Fighter();
            Stamina stamina = new Stamina();

            var attack       = new Attack(navMeshAgent, animator, stamina, maxNumberOfAttack, timeBetweenAttack);
            var moveToPlayer = new MoveToTarget(navMeshAgent, playerDetector, animator, moveSpeed, chaseSpeed,
                                                1f,//replace with weapon attack distance
                                                transform);
            var idle = new Idle(navMeshAgent, animator);


            Func <bool> CanAttack() => () => fighter.CanAttack(playerDetector.GetTarget());
            Func <bool> PlayerInRange() => () => playerDetector.TargetInRange;

            Func <bool> ShouldIdle() => () => { return(!(fighter.CanAttack(playerDetector.GetTarget()) && playerDetector.TargetInRange)); };

            _actionStateMachine.AddAnyTransition(attack, CanAttack());
            _actionStateMachine.AddAnyTransition(moveToPlayer, PlayerInRange());

            _actionStateMachine.AddTransition(moveToPlayer, idle, ShouldIdle());
        }
Beispiel #2
0
 private void InitHealthStateMachine()
 {
     _healthStateMachine = new AIStateMachine();
 }