Class PathEndingCondition

Public Abstract

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 {
// 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;
}
}
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.

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);
var ec = new MyEndingCondition(myPath);
ec.maxDistance = 100; // Or some other value
myPath.endingCondition = ec;

// Calculate the path!
seeker.StartPath(myPath);
Where seeker is a Seeker component.

If ending conditions are used that are not centered around the endpoint of the path, then the heuristic ( 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

PathEndingCondition (p)
Public
TargetFound (node, H, G)

Has the ending condition been fulfilled.

Public Abstract

Private/Protected Members

PathEndingCondition ()
Protected
path

Path which this ending condition is used on.

Protected