Large streaming world, world moving around origin to avoid float issue

I have a world sized 20000x20000. I managed to get the entire world loaded in the editor, and run a 90k set of Recast Graph tiles, took a fair amount of time. So now I have a complete graph, I have another issue to deal with.

As my player is moving around the world, new world tiles are moved into and out of memory. Since the entire world isn’t loaded at any given moment, and because large float values cause issues in Unity, I decided to load sections of my world around the Unity origin. So as the player moves, it seems to them they are moving across the world. They move across a tile, and when they get close to a tile edge, another tile is loaded, the far tile behind them is unloaded, and the entire world is shifted so that the player is again close to 0x0.

I understand that moving the graph is slow, but that I might not need to do that. I could query into the graph to get a path, and then somehow apply that path after having been transformed to the world position as it currently stands (the world is moving around the origin.)

While looking over the forum for information about doing this, I did find a few posts that had some leads. However, I was never able to nail down a solution. The closest I got was How can I attach my grid graph to my map and move them together? (Unity and C#), but the two links that Aron had didn’t work for me.

Can anyone share some guidance on how to transform a path?

I am using a Seeker and AI Path script, along with Opsive.UltimateCharacterController.Integrations.AstarPathfindingProject.AStarAIAgentMovement

I think I have a bit of code that will help me.
IAstarAIAgent.MovementUpdate(Time.fixedDeltaTime, out m_NextPosition, out m_NextRotation)

I think I could just apply a transform to m_NextPosition, and be done! gonna give that a try.

Hey,

You’re definitely not making it easy on yourself :wink:

If this is a single player experience you might be interested just re scanning the graph every now and then.

It is a single player experience. Please share where you feel I am going wrong. I am always interested in learning to build better projects!

Rather than pre calculating the entire graph you could periodically rescan the graph, based on the players delta position.

Hi

There is an example scene called “Moving” in the package which does sort of this. That example scene shows how to use pathfinding on a moving object like a ship without actually moving the graph.
You could probably use the same code.

Yes, Thank you Aron, this is exactly what I needed. I can use the information I learn in these “localspace” scripts to preform what I need. Thank you for the quick response, and for making this great tool.

  • Adam
1 Like