Calculate path but do not traverse it


#1

Hello

Is there a way to calculate a path without the Seeker traversing it?

I’m using a MultiTargetPath to work out some logic, before a second seeker.StartPath().

I’ve tried setting the isStopped and canMove booleans to false, along with setting the speed to zero directly after the first MultiTargetPath and before the second path, but nothing prevents movement on the first path.

In all circumstances, the gameObject begins to move on the first MultiTargetPath then adjusts to the second path shortly afterwards. I’m using the AILerp on a GridGraph if that makes any difference.

It seems like all this could simply be replaced with some sort of seeker.CalculatePathDontMoveMethod() but I’m failing to find anything like this in the documentation.

Thanks in advance.


#2

Hi

The movement scripts listen for all paths that the Seeker calculates currently.
You can either bypass the Seeker completely and call AstarPath.StartPath (see https://arongranberg.com/astar/docs/callingpathfinding.html), or you can modify the AILerp script a tiny bit to make it not listen to every single path calculation message.

Open the AILerp.cs script and remove the lines

seeker.pathCallback += OnPathComplete;

and

seeker.pathCallback -= OnPathComplete;

and then change the line

seeker.StartPath(currentPosition, destination);

to

seeker.StartPath(currentPosition, destination, OnPathComplete);

Note that the Seeker component is only intended to work with a single path request at a time, if you request a path while another path is already being calculated, the earlier path request will be cancelled. You can use path.BlockUntilCalculated to force paths to be calculated immediately.


#3

Hi Aron

Thank you for the speedy reply - it’s very much appreciated.

This is exactly what I’m looking for - I should have really investigated the AILerp.cs script, but was hesitant to modify package scripts. I’ll copy it and make a project version.

Thanks again for the assistance.