Moving mesh solution

Hi, I’m relatively new here, but I am currently using the Free version of the A* Pathfinding Project and definitely willing to purchase the Pro version if it will suit my needs. I am working on a project where my AI will be sailors moving on a moving ship. This ship is a model that I have purchased from the Unity asset store. I want my sailors to be able to move on the ship platform (this includes the floor and moving up some stairs). I have looked at the different types of graphs and have seen that neither a grid graph nor a nav mesh graph will suit my needs since the ship will move during runtime. I have thought of moving the world relative to the ship instead, but this will not work since I want multiple ships on the same world to have the same AI with the same capabilities. I know the pro version has something called a Recast graph which may benefit my needs but I’m unsure as to whether it will work or not since my ship does not have a very simple platform. (There are quite a few obstacles on the ship, but their meshes are unfortunately not separate from the ship itself)
All I really need my AI to do is walk to a specific destination given these constraints. What is the best way for me to achieve this?

Hmm it seems like a grid graph does suit my needs if the ship didn’t move at all.
I believe this solution may work but I’m not sure…
I don’t know if I can use one ship graph for multiple ships of the same type as long as I apply the same transformation (make the ShipData class not static, and have it be specific for different ships perhaps?)

Hi

Well, moving graphs is best done by some cheating.
Actually moving a graph would be very slow, however an easier solution is to: when you want to request a new path, convert the coordinates into local space (relative to the ship) then run pathfinding on that and when you later follow the path you convert the coordinates of the path into global coordinates again. In fact, in the pro version there is an example scene called “Moving” which shows pathfinding on a moving ship. That example scene uses a recast graph and a subclassed version of the RichAI movement script, however the principle is applicable to any movement script (but there are no included examples for other graphs at the moment).
This approach makes it slightly tricky to update the graph while it is moving however, but it is possible.

1 Like

So in the case of a grid graph, does this mean I must modify the existing AIPath class?
I’m setting a target destination through another script that controls my AI’s behavior

Also, if all my ships are the same can I use the same grid graph for every ship if all the ships start in the same orientation, but in different positions?
The ships will never change in any way so I believe graph updates apart for actual moving are not required.

Hi

Yes, in case of a grid graph you would have to modify the AIPath class.

Yes, actually I think it would be more complicated if you had multiple types of ships. What the script in the example scene does is that it assumes that the graph was scanned when the ship was at the world origin with no rotation.

1 Like

Actually all ships are the same type (the same prefab/same model). They have the same scale too and their initial rotation is 0, they just start at different positions.
I have a grid graph for one of my ships, is it possible that I can apply the same graph but for different ships?
I don’t care about collisions between sailors so that should not be an issue.
I just don’t want to build 10 or more graphs if I dont necessarily need to.
My AI will have the same functions on every ship.
(Perhaps each ship will have their own ship matrix to perform the appropriate transformation)

Yes. Since all ships would just use local space, and their local spaces are identical, they would all use the same graph placed at the origin of the world.

1 Like