protected override void Prepare() { if (startNode == null) { //Initialize the NNConstraint nnConstraint.tags = enabledTags; var startNNInfo = PathFindHelper.GetNearest(originalStartPoint, nnConstraint); startPoint = startNNInfo.position; startNode = startNNInfo.node; } else { startPoint = (Vector3)startNode.position; } #if ASTARDEBUG Debug.DrawLine((Vector3)startNode.position, startPoint, Color.blue); #endif if (startNode == null) { FailWithError("Couldn't find a close node to the start point"); return; } if (!CanTraverse(startNode)) { FailWithError("The node closest to the start point could not be traversed"); return; } }
protected override void Prepare() { nnConstraint.tags = enabledTags; var startNNInfo = PathFindHelper.GetNearest(startPoint, nnConstraint); startPoint = startNNInfo.position; endPoint = startPoint; startIntPoint = (Int3)startPoint; hTarget = (Int3)aim; //startIntPoint; startNode = startNNInfo.node; endNode = startNode; #if ASTARDEBUG Debug.DrawLine((Vector3)startNode.position, startPoint, Color.blue); Debug.DrawLine((Vector3)endNode.position, endPoint, Color.blue); #endif if (startNode == null || endNode == null) { FailWithError("Couldn't find close nodes to the start point"); return; } if (!CanTraverse(startNode)) { FailWithError("The node closest to the start point could not be traversed"); return; } heuristicScale = aimStrength; }
protected override void Prepare() { nnConstraint.tags = enabledTags; var startNNInfo = PathFindHelper.GetNearest(startPoint, nnConstraint); startNode = startNNInfo.node; if (startNode == null) { FailWithError("Could not find close node to the start point"); return; } }
/** Prepares the path. Searches for start and end nodes and does some simple checking if a path is at all possible */ protected override void Prepare() { //Initialize the NNConstraint nnConstraint.tags = enabledTags; var startNNInfo = PathFindHelper.GetNearest(startPoint, nnConstraint); //Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint var pathNNConstraint = nnConstraint as PathNNConstraint; if (pathNNConstraint != null) { pathNNConstraint.SetStart(startNNInfo.node); } startPoint = startNNInfo.position; startIntPoint = (Int3)startPoint; startNode = startNNInfo.node; if (startNode == null) { FailWithError("Couldn't find a node close to the start point"); return; } if (!CanTraverse(startNode)) { FailWithError("The node closest to the start point could not be traversed"); return; } // If it is declared that this path type has an end point // Some path types might want to use most of the ABPath code, but will not have an explicit end point at this stage if (hasEndPoint) { var endNNInfo = PathFindHelper.GetNearest(endPoint, nnConstraint); endPoint = endNNInfo.position; endNode = endNNInfo.node; if (endNode == null) { FailWithError("Couldn't find a node close to the end point"); return; } // This should not trigger unless the user has modified the NNConstraint if (!CanTraverse(endNode)) { FailWithError("The node closest to the end point could not be traversed"); return; } // This should not trigger unless the user has modified the NNConstraint if (startNode.Area != endNode.Area) { FailWithError("There is no valid path to the target"); return; } { // Note, other methods assume hTarget is (Int3)endPoint hTarget = (Int3)endPoint; hTargetNode = endNode; // Mark end node with flag1 to mark it as a target point pathHandler.GetPathNode(endNode).flag1 = true; } } }
protected override void Prepare() { nnConstraint.tags = enabledTags; var startNNInfo = PathFindHelper.GetNearest(startPoint, nnConstraint); startNode = startNNInfo.node; if (startNode == null) { FailWithError("Could not find start node for multi target path"); return; } if (!CanTraverse(startNode)) { FailWithError("The node closest to the start point could not be traversed"); return; } // Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint var pathNNConstraint = nnConstraint as PathNNConstraint; if (pathNNConstraint != null) { pathNNConstraint.SetStart(startNNInfo.node); } vectorPaths = new List <Vector3> [targetPoints.Length]; nodePaths = new List <GraphNode> [targetPoints.Length]; targetNodes = new GraphNode[targetPoints.Length]; targetsFound = new bool[targetPoints.Length]; targetNodeCount = targetPoints.Length; bool anyWalkable = false; bool anySameArea = false; bool anyNotNull = false; for (int i = 0; i < targetPoints.Length; i++) { var endNNInfo = PathFindHelper.GetNearest(targetPoints[i], nnConstraint); targetNodes[i] = endNNInfo.node; targetPoints[i] = endNNInfo.position; if (targetNodes[i] != null) { anyNotNull = true; endNode = targetNodes[i]; } bool notReachable = false; if (endNNInfo.node != null && CanTraverse(endNNInfo.node)) { anyWalkable = true; } else { notReachable = true; } if (endNNInfo.node != null && endNNInfo.node.Area == startNode.Area) { anySameArea = true; } else { notReachable = true; } if (notReachable) { // Signal that the pathfinder should not look for this node because we have already found it targetsFound[i] = true; targetNodeCount--; } } startPoint = startNNInfo.position; startIntPoint = (Int3)startPoint; if (!anyNotNull) { FailWithError("Couldn't find nodes close to the all of the end points"); return; } if (!anyWalkable) { FailWithError("No target nodes could be traversed"); return; } if (!anySameArea) { FailWithError("There are no valid paths to the targets"); return; } RecalculateHTarget(true); }