Function FollowerEntity.SetPath
Make the AI follow the specified path.
void SetPath (
Entity | entity | |
path | The path to follow. |
|
bool | updateDestinationFromPath=true | If true, the destination property will be set to the end point of the path. If false, the previous destination value will be kept. If you pass a path which has no well defined destination before it is calculated (e.g. a MultiTargetPath or RandomPath), then the destination will be first be cleared, but once the path has been calculated, it will be set to the end point of the path. |
Make the AI follow the specified path.
In case the path has not been calculated, the script will schedule the path to be calculated. This means the AI may not actually start to follow the path until in a few frames when the path has been calculated. The pathPending field will, as usual, return true while the path is being calculated.
In case the path has already been calculated, it will immediately replace the current path the AI is following.
If you pass null path, then the current path will be cleared and the agent will stop moving. Note than unless you have also disabled canSearch, then the agent will soon recalculate its path and start moving again.
Stopping the agent by passing a null path works. But this will stop the agent instantly, and it will not be able to use local avoidance or know its place on the navmesh. Usually it's better to set isStopped to false, which will make the agent slow down smoothly.
You can disable the automatic path recalculation by setting the canSearch field to false.
This call will be ignored if the agent is currently traversing an off-mesh link. Furthermore, when an agent starts traversing an off-mesh link, the current path request will be canceled (if one is currently in progress).
IEnumerator Start () {
var pointToAvoid = enemy.position;
// Make the AI flee from an enemy.
// The path will be about 20 world units long (the default cost of moving 1 world unit is 1000).
var path = FleePath.Construct(ai.position, pointToAvoid, 1000 * 20);
// Make the path use the same traversable tags and other pathfinding settings as set in the FollowerEntity inspector
path.UseSettings(ai.pathfindingSettings);
ai.SetPath(path);
while (!ai.reachedEndOfPath) {
yield return null;
}
}
This static method is used if you only have an entity reference. If you are working with a GameObject, you can use the instance method instead.
Make the AI follow the specified path.
void SetPath (
path | The path to follow. |
|
bool | updateDestinationFromPath=true | If true, the destination property will be set to the end point of the path. If false, the previous destination value will be kept. If you pass a path which has no well defined destination before it is calculated (e.g. a MultiTargetPath or RandomPath), then the destination will be first be cleared, but once the path has been calculated, it will be set to the end point of the path. |
Make the AI follow the specified path.
In case the path has not been calculated, the script will schedule the path to be calculated. This means the AI may not actually start to follow the path until in a few frames when the path has been calculated. The pathPending field will, as usual, return true while the path is being calculated.
In case the path has already been calculated, it will immediately replace the current path the AI is following.
If you pass null path, then the current path will be cleared and the agent will stop moving. Note than unless you have also disabled canSearch, then the agent will soon recalculate its path and start moving again.
Stopping the agent by passing a null path works. But this will stop the agent instantly, and it will not be able to use local avoidance or know its place on the navmesh. Usually it's better to set isStopped to false, which will make the agent slow down smoothly.
You can disable the automatic path recalculation by setting the canSearch field to false.
This call will be ignored if the agent is currently traversing an off-mesh link. Furthermore, when an agent starts traversing an off-mesh link, the current path request will be canceled (if one is currently in progress).
IEnumerator Start () {
var pointToAvoid = enemy.position;
// Make the AI flee from an enemy.
// The path will be about 20 world units long (the default cost of moving 1 world unit is 1000).
var path = FleePath.Construct(ai.position, pointToAvoid, 1000 * 20);
// Make the path use the same traversable tags and other pathfinding settings as set in the FollowerEntity inspector
path.UseSettings(ai.pathfindingSettings);
ai.SetPath(path);
while (!ai.reachedEndOfPath) {
yield return null;
}
}