Changing Position of Generated Graph

Hello,

The game I am making has the the player clicking to make units go to places on a moving ship. As a result, I need to be able to generate a graph at runtime (got that), and also, instead of changing the position of the graph and rescanning the entire thing, I would just like to change the position of all of the nodes, as there shouldn’t be any new obstacles, just a shift of the entire graph of nodes as is.

For instance, if the ship moves in the x direction 5 units, all of the nodes should move 5 units in the x direction. In addition, all agents with a path they are following need to also have their path modified to move 5 units in the x direction. If the graph rotates on the x axis, those nodes who are on the x axis line will not change position, but the further away they are from it the more they will move … etc

I don’t think it would be difficult to write a script which would keep track of all generated paths and the transform of the ship associated with that grid in order to update them myself as it moves about, but I imagine something like this is already handled somewhere in the program, which will automatically update all nodes / paths associated with a grid, instead of me doing all of them separately. I just can’t find where it is. I know you can rescan the whole graph, but because this thing will be constantly moving it’ll be very laborious on processing - much faster to just shift the positions of the nodes / paths, I think

Thanks

Hi

Do you have the pro version? If so you should take a look at the example scene named “Moving” which shows the exact case you are describing, complete with a ship and a character on it.

The trick is that you don’t move the graph at all, instead you transform all coordinates before interfacing with pathfinding. When requesting a path, you send the coordinates of the character relative to the ship, not relative to the world. When you follow the path, you transform the path’s coordinates from ship-coordinates back to world coordinates. This can be done easily using a matrix multiplication, or if you are lazy, ship.transform.TransformPoint and ship.transform.InverseTransformPoint.

Moving a graph is relatively slow, but faking movement using this method has almost no overhead at all.

I do not, but seeing as how I was needing the pro version anyway for multilayered grids anyway, it looks like I will be making a purchase in the future. Great product.

I would assume as much, but would what you described in the ‘Moving’ example scene work with a multilayered grid, as well?

Hi

Yes, that would work. Updating layered grid graphs is a bit slower than grid graphs, but it works.

PS: Sorry for the late answer, I have been away for a while and haven’t been able to answer many forum posts.