Hey there ![]()
if I understand you right, you would like to have a callback whenever you do calculate a path?
Had the same problem, and I did override the RichAI class to get something like that:
public class MovementAgent : RichAI
{
public event System.Action<Path> OnPathFound;
protected override void OnEnable()
{
base.OnEnable();
Reset();
}
public void Flee(Vector3 fleeFrom, float distance, float aimStrength = 1)
{
// The path will be returned when the path is over a specified length (or more accurately when the traversal cost is greater than a specified value).
// A score of 1000 is approximately equal to the cost of moving one world unit.
var theGScoreToStopAt = (int)(distance * 1000f);
// Create a path object
var path = FleePath.Construct(transform.position, fleeFrom, theGScoreToStopAt);
// This is how strongly it will try to flee, if you set it to 0 it will behave like a RandomPath
path.aimStrength = aimStrength;
// Determines the variation in path length that is allowed
path.spread = (int)Mathf.Max(4000, distance);
// Start the path and return the result to MyCompleteFunction (which is a function you have to define, the name can of course be changed)
seeker.StartPath(path, TrySendOnPathFound);
}
protected override void OnPathComplete(Path p)
{
base.OnPathComplete(p);
TrySendOnPathFound(p);
}
private void TrySendOnPathFound(Path p)
{
if (p.IsDone())
{
OnPathFound?.Invoke(p);
}
}
Hope this helps ![]()