Exemplo n.º 1
0
        public override TankState?act()
        {
            tankController.Aim();

            var tanks = tankController.tanksInCrashDistance(evadeRadius);

            if (tanks.Count <= 0)
            {
                return(previousState);
            }

            var evadeDir = Vector3.zero;

            foreach (var tank in tanks)
            {
                Vector3 dir = (gameObject.transform.position - tank.transform.position).normalized;

                // The weight is inversely related to how close this tank is the other tank.
                float weight = Mathf.InverseLerp(0f, evadeRadius,
                                                 (tank.transform.position - gameObject.transform.position).magnitude);
                evadeDir += dir * weight;
            }

            evadeDir.Normalize();
            tankController.GetComponent <NavMeshAgent>().destination =
                gameObject.transform.position +
                evadeDir * (evadeRadius + tankController.GetComponent <NavMeshAgent>().stoppingDistance + 10);
            return(null);
        }
Exemplo n.º 2
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.º 3
0
        public override TankState?act()
        {
            if (PlatoonHasRegrouped())
            {
                return(TankState.PATROLLING);
            }

            _tankController.GetComponent <NavMeshAgent>().destination =
                _tankController.platoonController.getPlatoonMeanPosition();
            return(null);
        }
Exemplo n.º 4
0
        public override TankState?act()
        {
            if (_tankController.platoonController.getEnemyTarget() != null)
            {
                return(TankState.CHASE);
            }

            _tankController.ResetAim();

            if (PlatoonHasReachedItsDestination())
            {
                _currentWayPointIndex = (_currentWayPointIndex + 1) % _wayPoints.Length;
            }
            _tankController.GetComponent <NavMeshAgent>().destination = _wayPoints[_currentWayPointIndex];
            return(null);
        }
Exemplo n.º 5
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);
        }