Point graph on moving platform (ship)

  • A* version: 5.2.5
  • Unity version: 2022.1.23f1

Hello
Im making ship game, where NPC should be able to walk on ships. As largest ship is going to have max 150 to 200 navingation points and max 25 to 30 agents, i was thinking point graph should be the simplest solution. Unfortunetly i cant wrap my head around how to move it with a ship.

Is there any fast and dirty way to deal with it? Performance is not an issue right now. I would like to avoid recast graph if possible. Not shure how to deal with open world where worlds 0.0.0 position is changed from time to time (dealing with floating point erorr)

There are no current plans for NPC to change ships so changing platforms isn’t a problem. Bigger problem will be steep almost vertical stairs and climing rigging.

Any pointers, you could give would be really aprriciated.

So, I was pretty sure that you could just scan the point graph when the parent game object moves, and yes! You can!

Here’s the quick dirty and badly performant code I wrote:

private Vector3 lastPosition;
private Quaternion lastRotation;
  
void Start()
{
    lastPosition = transform.position;
    lastRotation = transform.rotation;
}

void Update()
{
    if (Vector3.Distance(lastPosition, transform.position) > 1f) {
        AstarPath.active.Scan(AstarPath.active.data.pointGraph);
        lastPosition = transform.position;
    }

    if (Quaternion.Angle(lastRotation, transform.rotation) > 2f) {
        AstarPath.active.Scan(AstarPath.active.data.pointGraph);
        lastRotation = transform.rotation;
    }
}

And here’s the results:

i1206246992

But I do want to warn that I don’t think this will scale well. There’s ways to mitigate this, such as by only scanning the area of a ship rather than the entire point graph, scanning only when movement is requested/needed, etc- but even still, there’s this important note on the breakdown of graphs in the documentation, main points bolded:

Using this graph type is discouraged unless the other graph types just don’t work for your game.

Pros:

  • You are in full control over where nodes are placed. You can even make 3D pathfinding with this.
  • Fast to scan for simple cases, but can get very slow if you are not careful with your settings.

Cons:

  • Requires a lot of manual work to place all the nodes (or you have to write a script to do it automatically).
  • It’s hard to get good quality paths without a very large number of nodes.
  • Pathfinding is often slow due to the high node count that is required.
  • Slow graph updates.

Apparently it’s worth mentioning three times haha. But by all means, I could totally just be doomposting right now and it might be totally fine. Regardless the code is there if you want to use it :+1:

Yee, I wrote my own solution and it didnt go as planned at all… Moved to Recast gaph and dealing with its pathfinding problems xD

If you need help with that let us know :slight_smile:

Actually yee, Im stuck with recast graph and ood localSpaceRitchAI movement, its teleporting from time to time, Going to corners and getting stuck, on Link2. Using it for stairs on ship. Will try to put two link2 on each stairs, hoping it will solve atleast some of the problems.
Have feeling that navigation on moving platforms currently is a bit broken. Or it is just my seetings that are really broken.

graph settings


LocalSpaceRitchAi settings, local graph is added at runtime.

All target positions are behind a wall, doors are on layer that is beeing ignored by pathfinding

Had to write this code, because sometimes path just doesnt end where target is. while target is in navigable area. It also resets

        if (handler.localSpaceRichAI.reachedEndOfPath && handler.canMove && Vector3.Distance(handler.transform.position, handler.destinationSetter.target.position) < 0.3f)
        {
            status = EStatus.Succeed;
            return status;
        }
        else if (handler.localSpaceRichAI.reachedEndOfPath && handler.canMove && Vector3.Distance(handler.transform.position, handler.destinationSetter.target.position) > 0.3f)
        {
            timer -= delta;

            if (timer < 0f)
            {
                timer = 3f;
                handler.SetDestination(null);
                handler.SetDestination(moveToPosition);

                handler.localSpaceRichAI.SearchPath();
            }
        }

Are you using Off-mesh Links on the moving platform? Also can you provide a video of getting stuck in corners? I’ll better be able to understand what may be causing that if I see it.

Also I’m going to reply to your other questions from your other thread in this thread. Can you show me your scene setup in the Hierarchy?

Hi

I don’t think off-mesh links have been properly tested with the local space rich ai. If you register a custom callback to handle the traversal, it can probably work. But you’ll have to do some math in there to transform all coordinates to your ship coordinates.

Also keep in mind that the off-mesh links cannot move in world space. They must stay in the original position where the graph also is. The graph never actually moves, it’s just the agent that pretents that the graph is moving.

1 Like