A* Pathfinding Project
3.1.4
The A* Pathfinding Project for Unity 3D
|
Customized ending condition for a path. More...
Public Member Functions | |
PathEndingCondition (Path p) | |
virtual bool | TargetFound (NodeRun node) |
Has the ending condition been fulfilled. | |
Protected Attributes | |
Path | p |
Customized ending condition for a path.
This class can be used to implement a custom ending condition for e.g an Pathfinding::XPath.
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 stops 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 EndingConditionProximity and override the function TargetFound to specify our own logic.
One part at a time. We need to cast the node's position to a Vector3 since internally, it is stored as an integer coordinate (Int3). Then we subtract the Pathfinding::Path::originalEndPoint from it to get their difference. The original end point is always the exact point specified when calling the path. As a last step we check the squared magnitude (squared distance, it is much faster than the non-squared distance) and check if it is lower or equal to our maxDistance squared.
There you have it, it is as simple as that. Then you simply assign it to the endingCondition variable on, for example an XPath which uses the EndingCondition.
Where mySeeker is a Seeker component, and myXPath is an Pathfinding::XPath.
|
virtual |
Has the ending condition been fulfilled.
node | The current node. This is per default the same as asking if node == p.endNode |
Reimplemented in EndingConditionDistance, and ABPathEndingCondition.