示例#1
0
        public static Vector3 AdvoidObstacleBehaviour(OnlandVehicle tank, Vector3 currentSteering, Map map, float scanRadius = 50)
        {
            Vector3 originalScanVector = Vector3.Normalize(currentSteering) * scanRadius;
            //Vector3 originalSeePoint = currentTransform.Translation + originalScanVector;

            // scan around to find moveable position
            float rotateAngle = 0;
            float rotateStep  = MathHelper.PiOver4;

            List <float> availableAngles = new List <float>();
            Matrix       rotateMatrix;

            while (rotateAngle < MathHelper.TwoPi)
            {
                rotateMatrix = Matrix.CreateRotationY(rotateAngle);
                Vector3 scanPoint = tank.transformation.Position + Vector3.Transform(originalScanVector, rotateMatrix);

                if (tank.Moveable(scanPoint))
                {
                    availableAngles.Add(rotateAngle);
                    return(Vector3.Transform(currentSteering, rotateMatrix));
                }

                rotateAngle += rotateStep;
            }

            if (availableAngles.Count == 0)
            {
                return(tank.transformation.WorldMatrix.Backward);
            }

            availableAngles.Sort(new AngleComparer());
            rotateMatrix = Matrix.CreateRotationY(availableAngles[0]);
            return(Vector3.Transform(currentSteering, rotateMatrix));
        }
示例#2
0
        public void SpawnEnemyTank()
        {
            for (int i = 0; i < spawnMaxAttempt; i++)
            {
                Random  r               = new Random();
                int     spawnIndex      = r.Next(map.SpawnPoints.Count);
                Vector3 newTankLocation = map.SpawnPoints[spawnIndex];
                newTankLocation.Y = map.GetHeight(newTankLocation);

                OnlandVehicle enemyVehicle = VehicleFactory.CreateTank(ModelType.TANK1, 60);
                enemyVehicle.Tag = "Enemy";
                enemyVehicle.transformation.Position = newTankLocation;
                enemyVehicle.AddToGameWorld();
                if (enemyVehicle.Moveable(newTankLocation))
                {
                    enemyVehicle.AddComponent(new EnemyTankAI());
                    break;
                }
                else
                {
                    enemyVehicle.RemoveFromGameWorld();
                }
            }
        }