Exemple #1
0
    public List <Transform> GetPath(Vector3 startPos, Vector3 endPos)
    {
        Tile             startTile = _generator.FindClosestTile(startPos);
        Tile             endTile   = _generator.FindClosestTile(endPos);
        List <Transform> path      = GetPath(startTile, endTile);

        //path.Add(endEntity);
        return(path);
    }
Exemple #2
0
    void MoveToNewRandomTile(Transform t)
    {
        // Remove the oldest tile in recent list as we're adding a new one.
        if (_stateMachine.recentTiles.Count >= _stateMachine.recentListLength)
        {
            _stateMachine.recentTiles.RemoveAt(0);
        }

        // Get a list of all neighbors, pick a random one we haven't been on.
        List <Tile> neighbors = new List <Tile> (_generator.FindClosestTile(t.position).neighbors);

        neighbors = neighbors.OrderBy(x => Random.value).ToList(); // Shuffle our neigbor list copy.
        List <Tile> options = new List <Tile>();

        foreach (Tile tile in neighbors)
        {
            if (!_stateMachine.recentTiles.Contains(tile))
            {
                _tank.waypointList.Add(tile.transform);
                _stateMachine.recentTiles.Add(tile);
                return;
            }
            else
            {
                options.Add(tile);
            }
        }
        // If we've gotten to this point, we are surrounded by tiles we've been on, pick the oldest one.
        foreach (Tile tile in _stateMachine.recentTiles)
        {
            if (options.Contains(tile))
            {
                _tank.waypointList.Add(tile.transform);
                _stateMachine.recentTiles.Add(tile);
                return;
            }
        }
        //System.GC.Collect();
    }