예제 #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);
        }
예제 #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);
        }