Hi everyone,
I’m new to unity, so sometimes I run into problems that I can’t solve on my own. Not knowing English is also not good for successful search of information.
At the moment I am facing a floating point problem when moving away from the coordinate origin. I don’t have such a huge map (only 5000x5000 units), but already at a distance of 2000 units from the coordinate origin I see jittering.
I am aware of this problem. But for me it was a surprise that it starts to happen relatively close to the origin (a little more than 1000 units from the origin and already jittering appears, which increases with distance). I’ve read solving the problem by shifting the origin with the player, but I’ve also read that this brings some problems. Plus, all the articles and tutorials I found were pretty old (2018-2020). Hasn’t anything changed for the better now in 2024?
Maybe someone can give me a modern solution to this problem. How can I make a 5000x5000 unit (5x5km) open world so that I don’t have problems with jittering animated objects?
I am using Unity 2022.3
Hi alexsecl,
This is a common problem especially for FPS games and large open worlds. Third person camera is not as noticeable since the camera is much farther away from the player.
Try this free asset:
[Origin Shift - Multiplayer Infinite World Solution](http://Origin Shift - Multiplayer Infinite World Solution)
Origin Shift - Multiplayer Infinite World Solution | Network | Unity Asset Store
There is a demo included in the package. Let me know if it works for you.
The most common way to address this issue is by periodically shifting the entire world AND player back to the origin while keeping the players position in the 3D environment relative so the game is not affected. Most solutions to do this have an exposed variable for how often you want the shift to occur. 500 meters or whenever you start noticing the jittering like in your image. Be careful because navmeshes can be tricky, but the above free asset addresses this. You can also use root motion for NPC’s to avoid this altogether.
Hope this helps! If you have any other questions about building large open worlds in unity, please let me know. I’m happy to help if can.
(EDIT clarification on shifting relativity and navmeshes)
Thanks for the advice!
I tried this asset in my project. Unfortunately I encountered some problems. My project uses splat shaders to display wheel marks on the sand. When using the Origin Shift asset, the wheel marks move in space with the character.
Are you using a specific vehicle controller? There are many options within the above asset. Once of them is continuous update…this could really mess up your wheel marks on the ground. You’ll definitely need to play around with it. Try unticking the defaults. Try updating every 500-1000 meters. Worst case you should only lose your tire marks when the shift happens. If it’s on constant update (every frame) that’s not only resource intensive but also your wheel marks will run into issues. Without knowing your controller, I really couldn’t say much beyond that.
If you can’t find a solution in the documentation, then you might need to adjust your controller or how you do your wheel marks. It’s hard to say what you should do without knowing more details. I know nothing about the project you are working on. You can pm me if you don’t want to put that info public. I noticed in the description that realistic car controller is supported by the asset. That asset uses tire marks. The secret might be looking at how that is implemented and/or using that controller. There are also many other solutions to going about this. The one I suggested is just the free option I know about.
The car controller I have is pretty standard. And for sand trails, I use the asset MicroSplat - Trax: MicroSplat - Trax | Terrain | Unity Asset Store
Yes, when I turned off the world update at every frame, and set the trigger distance at 1000 meters, it got better. The tracks shift, but it happens very rarely and is not as noticeable.
I haven’t figured it out exactly yet, but is there a problem with the camera that is controlled by the cinemachine? When the origin shifts, the cinemachine camera behaves strangely for a few seconds and then levels off.
And I also can’t yet figure out how I can implement saving the position of objects in space for later loading. If I don’t use the Origin Shift Asset, when I click save, I save the current position of the character (e.g. vector3d 1245:8:502). And load it when the game continues.
But when using Origin Shift, the position of the world and objects will shift. How do I save and load the correct position of the character and objects?
This is decent trade-off imo.
I don’t know what is causing this because I don’t really use cinemachine. I’ve tried it and I don’t like it personally for a number of reasons. I’ve never encountered this problem with camera solutions with made for various controllers I’ve tested.
You need to organize your scene so that every single part of your level is under the same parent object. Most controllers and systems usually have a way to save the position of game objects. This is often done by registering the object with the save system you are using, commonly by attaching the appropriate save game component to your parent game object. This will subsequently save the position of all game objects under your parent game object containing your level / environment.
If you are using a third party save system, there will most likely be documentation on how to save the position of non-player game objects. If it doesn’t, then you’ll need to use a more fully featured save system.