Hi,
I have an issue where point graphs that are moved using RelocateNodes are not being included in pathfinding.
For some back story, I am making a game with procedural dungeons where rooms link together. I add a surface in between the doors that the Recast pathfinder will use as a potential area to move between the rooms.
The Recast graphs work, I translate it using the same matrix calculation as the point graphs. The enemies are able to traverse between rooms that are loaded in from a cache and relocated. The problem is, they are fine in the room where the original cache is from, but enemies from another room are not able to pathfind including their node links. The behaviour I see from the second room is that the moment I go to a higher position, they run in circles. In the same area in the original room, they are able to jump. I am loading the same cache (as it is the same room twice for testing purposes) and I start with an empty pathfinder.
When the pathfinder is in play mode, both graphs are loaded from the same cache and relocated for each room:
This is an image of the original room, with a loaded cache and relocated nodes (they aren’t moved from original position, the matrix is essentially blank, but it is loaded in)
This is an image of the second room, seemingly identical, and loaded the same way. The matrix would be a 180 degree rotation and a slight offset in position.
This is my code to relocate the nodes:
AstarPath.active.data.DeserializeGraphsAdditive(AStarCache.bytes);
Matrix4x4 graphMatrix = Matrix4x4.identity;
graphMatrix *= Matrix4x4.Translate(transform.position);
graphMatrix *= Matrix4x4.Rotate(transform.rotation);
graphMatrix *= Matrix4x4.Translate(-transform.position);
graphMatrix *= Matrix4x4.Translate(transform.position - startingPosition);
var graphs = AstarPath.active.graphs;
int pointGraphIndex = graphs.Length - 1;
int recastGraphIndex = graphs.Length - 2;
if (graphs[pointGraphIndex] is PointGraph)
{
Debug.Log("Moving a point graph!");
var g = graphs[pointGraphIndex] as PointGraph;
g.RelocateNodes(graphMatrix);
g.Scan();
}
if (graphs[recastGraphIndex] is RecastGraph)
{
Debug.Log("Moving a recast graph!");
var g = graphs[recastGraphIndex] as RecastGraph;
g.RelocateNodes(graphMatrix);
}
Here is a video of the behaviour.