Vector3 PickBFSNode(int maxDistance) { var startNode = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node; var nodes = PathUtilities.BFS(startNode, maxDistance); return(PathUtilities.GetPointsOnNodes(nodes, 1)[0]); }
public Vector3 BFSWanderPoint() { // Get a random point for wander var startNode = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node; var nodes = PathUtilities.BFS(startNode, 100); var singleRandomPoint = PathUtilities.GetPointsOnNodes(nodes, 1)[0]; //var multipleRandomPoints = PathUtilities.GetPointsOnNodes(nodes, 100); return(singleRandomPoint); }
public List <Vector3Int> CalculateMovementRange(Vector3Int startingCell, int range) { Int3 startingNodePos = (Int3)(Vector3)startingCell; PointNode initialNode = Array.Find(pathfindingGraph.nodes, node => node.position == startingNodePos); List <GraphNode> reachableNodes = PathUtilities.BFS(initialNode, range, -1, node => { Vector3Int nodeCellPos = Int3ToCellPos(node.position); bool result = nodeCellPos == startingCell || !IsTileTaken(nodeCellPos); return(result); }); List <Vector3Int> moves = new List <Vector3Int>(); foreach (GraphNode node in reachableNodes) { if (node.position != startingNodePos) { moves.Add(Int3ToCellPos(node.position)); } } return(moves); }