Support Forum

Local Space AI Path, LocalSpaceRichAI equivalent for 2D

I just bought A* pathfinding today and I’m still getting to grips with it.

I’m working on a project in 2D and I would like to employ the equivalent of the “Moving” demo, which uses the LocalSpaceRichAI. I notice from a comment in the AIBaseEditor class that Rich AI is not compatible with 2D and is exclusively designed for XZ traversal.

I’ve therefore been trying to get an equivalent set up for AIPath i.e LocalSpaceAIPath, the documentation for LocalSpaceRichAI suggests it should be relatively straightforward to convert the logic and I basically understand what is being done behind the scenes - perform pathfinding at a graph at zero space and inverse transform the path at runtime, but for the life of me I can’t seem to get it working.

I was hoping somebody could shed some light on how the LocalSpaceRichAI actually does local space pathfinding in a bit more detail and give any pointers towards replicating that logic.

Hi

You can make a LocalSpaceAIPath by copy-pasting that script into a new one and changing the base class from RichAI to AIPath. However you need a few extensions to the AIPath script.

You need to add a GraphTransform field to the PathInterpolator class and for all Vector3 parameters that functions get you need to call transform.InverseTransform(value) and for all Vector3 values that are returned from methods and properties in that class you need to call transform.Transform(value).

Then in the LocalSpaceAIPath you need to replace the

richPath.transform = graph.transformation;

line with

interpolator.transform = graph.transformation;

I haven’t tried this myself, but I think this should work.