Ejemplo n.º 1
0
    private List <Vector3> FindNearestCorners(Commander enemy, Obstacle.BoxColliderDescriptor obstacle)
    {
        Vector3 corner1      = Vector3.zero;
        Vector3 corner2      = Vector3.zero;
        float   nearestDist1 = float.MaxValue;
        float   nearestDist2 = float.MaxValue;

        for (int i = 0; i < obstacle.xzBoundaries.Count; i++)
        {
            float dist = Vector3.Distance(enemy.transformRef.position, new Vector3(obstacle.xzBoundaries[i].x, enemy.transformRef.position.y, obstacle.xzBoundaries[i].y));

            if (dist < nearestDist1)
            {
                nearestDist2 = nearestDist1;
                nearestDist1 = dist;
                corner2      = corner1;
                corner1      = new Vector3(obstacle.xzBoundaries[i].x, enemy.transformRef.position.y, obstacle.xzBoundaries[i].y);
            }

            else if (dist < nearestDist2)
            {
                nearestDist2 = dist;
                corner2      = new Vector3(obstacle.xzBoundaries[i].x, enemy.transformRef.position.y, obstacle.xzBoundaries[i].y);
            }
        }
        return(new List <Vector3> {
            corner1, corner2
        });;
    }
Ejemplo n.º 2
0
    private Vector3 FindFarthestFace(Commander enemy, Obstacle.BoxColliderDescriptor obstacle)
    {
        Vector3 corner1       = Vector3.zero;
        Vector3 corner2       = Vector3.zero;
        float   farthestDist1 = 0;
        float   farthestDist2 = 0;

        for (int i = 0; i < obstacle.xzBoundaries.Count; i++)
        {
            float dist = Vector3.Distance(enemy.transformRef.position, new Vector3(obstacle.xzBoundaries[i].x, enemy.transformRef.position.y, obstacle.xzBoundaries[i].y));

            if (dist > farthestDist1)
            {
                farthestDist2 = farthestDist1;
                farthestDist1 = dist;
                corner2       = corner1;
                corner1       = new Vector3(obstacle.xzBoundaries[i].x, enemy.transformRef.position.y, obstacle.xzBoundaries[i].y);
            }

            else if (dist > farthestDist2)
            {
                farthestDist2 = dist;
                corner2       = new Vector3(obstacle.xzBoundaries[i].x, enemy.transformRef.position.y, obstacle.xzBoundaries[i].y);
            }
        }
        Vector3 faceMidPoint = corner2 + (corner1 - corner2) / 2;

        cornerA = corner1;
        cornerB = corner2;
        return(faceMidPoint);
    }
Ejemplo n.º 3
0
    private void FindRandomCover()
    {
        includedObstacles = new List <Obstacle.BoxColliderDescriptor>(Game.Instance.covers);

        foreach (Commander enemy in _enemies)
        {
            int excludedCount = Physics.OverlapSphereNonAlloc(enemy.transformRef.position, 15f, excludedObstacles);
            for (int i = 0; i < excludedCount; i++)
            {
                Obstacle.BoxColliderDescriptor obstacle = excludedObstacles[i].GetComponent <Obstacle.BoxColliderDescriptor>();
                if (obstacle)
                {
                    includedObstacles.Remove(includedObstacles.Find(obs => obs.Equals(obstacle)));
                }
            }
        }

        int trial = 0;

        do
        {
            int randomIdx = Random.Range(0, includedObstacles.Count);
            if (!includedObstacles[randomIdx].isOccupied)
            {
                _selectedCover = includedObstacles[randomIdx];
            }
        } while (_selectedCover == null || ++trial < Game.Instance.covers.Count);

        if (_selectedCover != null)
        {
            _selectedCover.isOccupied = true;
        }
    }
Ejemplo n.º 4
0
 private void LeaveLastCover()
 {
     if (_selectedCover != null)
     {
         _selectedCover.isOccupied = false;
     }
     _selectedCover = null;
 }
Ejemplo n.º 5
0
    private void FindNearestCover()
    {
        float nearestDist = float.MaxValue;

        foreach (Obstacle.BoxColliderDescriptor cover in Game.Instance.covers)
        {
            float dist = Vector3.Distance(cover.transformRef.position, transformRef.position);
            if (dist < nearestDist && cover.isOccupied == false)
            {
                nearestDist    = dist;
                _selectedCover = cover;
            }
        }
        _selectedCover.isOccupied = true;
    }