private void MakeOneStepTowardsTheTarget() { Vector3Int startNode = tilemap.WorldToCell(transform.position); Vector3Int endNode = targetInGrid; //List<Vector3Int> shortestPath = BFS.GetPath(tilemapGraph, startNode, endNode, maxIterations); List <Vector3Int> shortestPath = Dijekstra.GetPath(tilemapGraph, startNode, endNode); Debug.Log("shortestPath = " + string.Join(" , ", shortestPath)); if (shortestPath.Count >= 2) { Vector3Int nextNode = shortestPath[1]; transform.position = tilemap.GetCellCenterWorld(nextNode); } else { atTarget = true; } }
private void MakeOneStepTowardsTheTarget() { Vector3Int startNode = tilemap.WorldToCell(transform.position); Vector3Int endNode = targetInGrid; //Apply Dijkstra algorithm to find the shortest Path with weights List <Vector3Int> shortestPath = Dijekstra.GetPath(tilemapGraph, startNode, endNode); Debug.Log("shortestPath = " + string.Join(" , ", shortestPath)); if (shortestPath.Count >= 2) { Vector3Int nextNode = shortestPath[1]; transform.position = tilemap.GetCellCenterWorld(nextNode); //find and set the speed for each tile TileBase currTileBase = TileOnPosition(transform.position); int TileWeight = allowedTiles.getWeights()[allowedTiles.findTilePos(currTileBase)]; timeBetweenSteps = TileWeight / speed; } else { atTarget = true; } }