Exemplo n.º 1
0
        public override TankState?act()
        {
            var target = tankController.platoonController.getEnemyTarget();

            // no targets -> regroup
            if (target == null)
            {
                return(TankState.REGROUPING);
            }

            // enemies in attackRange -> attack
            if (tankController.EnemiesInAttackRange().Count > 0)
            {
                return(TankState.ATTACKING);
            }

            // calculate the nearest position in the middle of the attack range
            var directionFromEnemyToPlayer = (tankController.transform.position -
                                              target.transform.position)
                                             .normalized;

            var dest = target.transform.position + directionFromEnemyToPlayer *
                       (tankController.maxAttackRange - tankController.minAttackRange);

            // move towards it
            tankController.GetComponent <NavMeshAgent>().destination = dest;
            return(null);
        }
Exemplo n.º 2
0
        public override TankState?act()
        {
            //Check for current targets and enemies in range.
            currentTargets = platoonController.getCurrentTargets().Count;
            enemiesInRange = tankController.EnemiesInAttackRange().Count;

            // aim and if target is locked -> shoot
            currentTarget = platoonController.getEnemyTarget();
            tankController.Aim();

            var tanks = tankController.tanksInCrashDistance(EvadeState.evadeRadius);

            if (tanks.Count > 0 && !tankController.checkLineOfSight())
            {
                EvadeState.previousState = TankState.ATTACKING;
                return(TankState.EVADING);
            }

            //Check line of sight
            if (tankController.checkLineOfSight())
            {
                //Line of sight clear, dodge and shoot
                tankController.Shoot();
            }

            if (enemiesInRange == 0 && currentTargets != 0)
            {
                return(TankState.CHASE);
            }

            // no more enemies around -> regroup
            if (enemiesInRange == 0 && currentTargets == 0)
            {
                return(TankState.REGROUPING);
            }

            //Move towards the calculated destination
            tankController.GetComponent <NavMeshAgent>().destination = destination * (tankController.GetComponent <NavMeshAgent>().stoppingDistance + 10);

            return(null);
        }