Class PathEndingCondition
Customized ending condition for a path.
If you want to create a path which needs a more complex ending condition than just reaching the end node, you can use this class. Inherit from this class and override the TargetFound function to implement you own ending condition logic.
For example, you might want to create an Ending Condition which stop searching when a node is close enough to a given point. Then what you do is that you create your own class, let's call it MyEndingCondition and override the function TargetFound to specify our own logic. We want to inherit from ABPathEndingCondition because only ABPaths have end points defined.
public class MyEndingCondition : ABPathEndingCondition {
The TargetReached method in the code above checks if the node that the path is currently searching is close enough to the target point for us to consider it a valid target node. If true is returned, the path will immediately terminate and return the path to that point.
// Maximum world distance to the target node before terminating the path
public float maxDistance = 10;
// Reuse the constructor in the superclass
public MyEndingCondition (ABPath p) : base(p) {}
public override bool TargetFound (GraphNode node, uint H, uint G) {
return ((Vector3)node.position - abPath.originalEndPoint).sqrMagnitude <= maxDistance*maxDistance;
}
}
To use a custom endition condition, you have to instantiate your class and then assign it to ABPath.endingCondition field.
ABPath myPath = ABPath.Construct(startPoint, endPoint);
Where seeker is a Seeker component.
var ec = new MyEndingCondition(myPath);
ec.maxDistance = 100; // Or some other value
myPath.endingCondition = ec;
// Calculate the path!
seeker.StartPath(myPath);
If ending conditions are used that are not centered around the endpoint of the path, then the heuristic (\reflink{AstarPath.heuristic) must be set to None to guarantee that the path is still optimal. However, the performance impact of setting the heuristic to None is quite large, so you might want to try to run it with the default heuristic to see if the path is good enough for your use case anyway.
Public Methods
Has the ending condition been fulfilled.