public void CreateFlowField() { foreach (Cell curCell in grid) { curCell.bestDirection = GridDirection.None; List <Cell> curNeighbors = GetNeighborCells(curCell.gridIndex, GridDirection.AllDirections); int bestCost = curCell.bestCost; foreach (Cell curNeighbor in curNeighbors) { if (curNeighbor.bestCost < bestCost) { bestCost = curNeighbor.bestCost; curCell.bestDirection = GridDirection.GetDirectionFromV2I(curNeighbor.gridIndex - curCell.gridIndex); } } } }