Recast graph on a moving surface
Example scene which demonstrates navigation on a moving surface.
This movement scene is a bit different. The agent moves around on a spaceship that is simultaneously moving around in space.
Contents
Graph setup
Moving every single node in the graph every frame would be slow, and propagating this information to already calculated paths would also be pretty tricky. So instead, the movement script that we use here ( LocalSpaceRichAI) cheats.
The graph in the scene is actually static. It stays in the same position as the ship moves around. However, when the graph is scanned as the game starts, the position of the ship is recorded. When it is time to calculate a path, the movement script will transform its position and destination so that it looks as if the ship was still at its initial position. This means it will match the scanned graph perfectly. Similarly, when it follows the path, it will transform all points on the path to account for the current position and rotation of the ship.
This has some limitations, for example navmesh cutting and other graph updates will not work. But following a path works just fine regardless of how the ship moves.
Detailed setup
The scene is configured like this:
The ship is added. This can be any mesh or collection of meshes.
A recast graph is added, and configured to cover the ship at its initial position.
An agent is added as a child of the ship GameObject. This ensures that it will move with the ship.
The LocalSpaceGraph component is added to the ship GameObject. This will track the initial position of the ship, and provide the means for the agent to translate back and forth between the ship's coordinate system and the world coordinate system.
The LocalSpaceRichAI component is added to the agent, and the LocalSpaceGraph component is assigned to its LocalSpaceRichAI.graph field.
The ship is made to move using the BezierMover component. This component moves the ship through a series of points, along a smooth curve.