Hello,
I have a movement script that gets enabled and disabled depending on the current state of the AI. So the first time I use the script and check
private void Update()
{
_aStarAi.destination = target.position;
if (_aStarAi.reachedEndOfPath)
{
Debug.Log("Destination reached!");
IsCompleted = true;
}
else
{
Debug.Log("Not reached!");
}
}
Seems to be working but then I go in another state and at some point I enabled the movement script again and it immediately prints “Destination reached” and after a less than a second it starts printing “Not reached” which makes me think it’s taking awhile to calculate the new path and prints Destination reached using the previous path. So how do I fix that? I have tried adding another check for “pathPending” but it still doesn’t work.
EDIT : I think it has something to do with the RepathRate, the bigger that value is the longer the AI circles around it’s old path and prints “Destination Reached”. But even if it’s 0 it still prints “Destination Reached” once or twice which is not something I’d like because when a destination is reached the movement script is disabled automatically.
Is there a way to “clear” the most recent path when disabling the movement script so next time it’s enabled it will start fresh without having a calculated path (with the previous player’s position which is no longer relevant).
EDIT 2 : It seems like doing this inside OnEnable fixes the issue, but I am still waiting for the developer to respond to make sure it’s the right way to do it.
_richAi.destination = target.position;
_richAi.SearchPath();