Multi-layered movement on "moving" graph

Hi,

I have just recently purchased the pro version of the a* pathfinding project, and I am trying to use it to create a moving/rotating spaceship with AI on board.

So far, I am making some progress. I am using the “moving” example script, and this seems to work ok, but apparently it doesn’t work with node links.

I found this thread:

Which seems to prove this, apparently the Rich AI script doesn’t support the multi-level graphs?

Is this still true? What would be the easiest way to fix this? I have multiple decks/compartments,etc, on my ship object, so I need to be able to use multi-level graphs.

Hey,

There are 3 movement scripts included in this package, AIPath is a great alternative to Rich Ai.

You can read more about the various movement scripts here: https://arongranberg.com/astar/docs/old/movementscripts.php

Wolf

@ZeroSum

The RichAI movement script is only for navmesh based graphs (i.e. the navmesh and the recast graph). See https://arongranberg.com/astar/docs/movementscripts.html. RichAI works perfectly well with a layered environment when using the recast or navmesh graph.

You are right though that on a moving graph, off mesh links are not yet supported. You could make it work by setting the RichAI.onTraverseOffMeshLink delegate from another script to take control over the link traversal completely however.
Note also that the off mesh links need to be positioned in graph space where the nodes actually are. They cannot move around with the rest of the ship (or at least not without some minor modifications).

Thanks for those replies.

So, it seems like I have two options:

Use AIPath instead of richai (which I would need to modify to create a “local space” version?),

or modify the RichAI.ontraverseoffmeshlink delegate from RichAI?

Well, AIPath on a moving graph wouldn’t work with off mesh links either. So the work for AIPath is strictly greater than with RichAI.

Oh ok, so I’m better off with Rich AI?

I’m using a recast graph, and it seems to work ok without rotation/movement, so I just need to look into these traverseoffmeshlink delegates?

Yes, I think you are better off with RichAI.

Thank you.

How would I go about modifying the richAI script?

I have found a “TraverseSpecial” function, but I’m not sure how to modify that?

All I really need is basic functionality, if I could even get the AI to “warp” from the off mesh link points that would work fine.

You do not need to modify the RichAI script itself, you can just subscribe to that delegate.

See the documentation here: https://arongranberg.com/astar/docs/richai.html#onTraverseOffMeshLink

Thanks, I have delegates working now.

So, all I need to do now is to modify this:

        IEnumerator TraverseOffMeshLink(RichSpecial link)
        {
            print("traversing offmesh link...");

            // Traverse the link over 1 second
            float startTime = Time.time;

            while (Time.time < startTime + 1)
            {
                transform.position = Vector3.Lerp(link.first.position, link.second.position, Time.time - startTime);
                yield return null;
            }
            transform.position = link.second.position;
        }

To handle the transformation between the origin point of the graph and the translated point when the AI is using the off mesh link?

Exactly.
So you need to use localSpaceGraph.Transform or localSpaceGraph.InverseTransform for the respective points to transform them from graph space to local space (or vice versa).

I’m looking through the LocalSpaceRichAI script, and I can’t seem to see where to use the transform functions.

I get that I need to change this:

transform.position = link.second.position;

using graph.transform, but how is that done?

This:
transform.position = graph.transformation.Transform(link.second.position);

seems to solve the issue.

Rotation of the parent object now basically works, but there seem to be a few issues that “break” the rotation.

I think it might be because I am stopping and starting the AI using “can move true/false” and the AI’s position changes while canmove is set to false.

Do you know of any preexisting issues with doing this?

Thanks a lot for your help!

Hi

It might be better to use the ai.Teleport method which is specifically designed for this use case. It takes care of updating all the internal fields properly.

Hi, thanks for your reply, I seem to have fixed most of my issues. I think the AI is rotating correctly now. Great resource!

1 Like