Can RichAI return a smoothed path on Recast gaph like Unity Navigation does?

The path returned by the Seeker component calculated from a Recast graph is, I’m sure you know, very rough. RichAI will follow this path itself in a much smoother fashion, making it much more usable. However I would like just a smoothed path and then to go along that path with my own code. Is it possible to just get smoothed path on a recast graph like you can with Unity’s Navmesh system? If not, is there any particular reason why?

Hi

TL;DR: Follow the get started tutorial: https://arongranberg.com/astar/docs/getstarted.php
but instead of attaching the SimpleSmoothModifier attach the FunnelModifier.

Like the Unity navmesh agent, the RichAI script does not first smooth the path and then follow it. Instead it just finds the next corner it has to move to each frame. So at no point does it know how the full smoothed path looks like.

However if you attach the FunnelModifier to the same GameObject as the Seeker/RichAI then that modifier will smooth the path just like the RichAI would do. You can then get the smoothed path using

 seeker.GetPath().vectorPath

or register to the Seeker for a callback

seeker.pathComplete += path => {
    var vectorPath = path.vectorPath;
}

The RichAI will completely ignore this smoothed information , however if you would have used another movement script such as the AIPath movement script, it will use it. The AIPath script only follows a sequence of 3D points while the RichAI movement script is more specialised for navmesh-based graphs (i.e not grids or point graphs).

Thank you very much for the information, Aron.

So if I were to nutshell this explanation, are you saying that “RichAI” component is basically just “FunnelModifier” + “AIPath”?

By combining the FunnelModifier and AIPath, there shouldn’t be any problems that it’s a RecastGraph? Will I be losing any functionality of the RichAI?

Essentially. The RichAI script can do a few more things like constrain the AI to the navmesh (the AIPath script has no idea where the boundaries of the navmesh area) and it is slightly more resistant to loosing its way if you push it too far away from the original path. Usually the AIPath script will work just as well.

I wanted to clarify on this so that you knew, but you can actually get a smoothed path of Vector3 back from the NavMeshAgent without it moving at all. I have been doing this with great results for years now by using the following method:

UnityEngine.AI.NavMesh.CalculatePath(Vector3, Vector3, int, NavMeshPath)

This brings back a smoothed path I can manually follow that sticks perfectly to the Navmesh itself. Maybe you can dig into that and implement that (extremely useful) functionality into this project.

Yes. That can be done. Essentially this would be the corresponding code:

 var path = seeker.StartPath(start, end);
 path.BlockUntilCalculated();
 // result is in path.vectorPath

This assumes that you have a Seeker component attached and a FunnelModifier attached. This mimics the Unity call in that it is synchronous. You may want to use an asynchronous version if you have long paths

 var path = seeker.StartPath(start, end);
 // wait a few frames (usually 1 for short paths)
 yield return StartCoroutine(path.WaitForPath());
 // result is in path.vectorPath

Note that if you have one of the built in movement scripts attached to the same GameObject, it will also be notified that a new path was calculated and it will begin to follow it. It is also possible to avoid this. I can explain this if you need it.

I tried this out and it worked perfectly. Thank you for the help, Aron!