Function IAstarAI.SetPath

SetPath (Path path, bool updateDestinationFromPath=true)

Make the AI follow the specified path.

Public
void SetPath (

Path

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.

)

Make the AI follow the specified path.

In case the path has not been calculated, the script will call seeker.StartPath to calculate it. 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. This is useful if you want to replace how the AI calculates its paths.

If you pass null as a parameter 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.

You can disable the automatic path recalculation by setting the canSearch field to false.

Note

This call will be ignored if the agent is currently traversing an off-mesh link. Furthermore, if the agent starts traversing an off-mesh link, the current path request will be canceled (if one is currently in progress).

// Disable the automatic path recalculation
ai.canSearch = false;
var pointToAvoid = enemy.position;
// Make the AI flee from the 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);
ai.SetPath(path);