Floating Origin in Unity
This technique is used when you need a larger area than the standard range in Unity. Transform position loses precision at around 10km (1 unit = 1 meter). Shadow mapping much closer.
The idea is very similar to old-school games, where the character is always in the center of the screen and the world scrolls under him.
Let’s assume I have a huge map, which somehow consists of world tiles, which are dynamically loaded/generated. I also have a character, some enemies and the camera.
First thing is that all these elements get a 64-bit ‘real’ position, so
{ double x; double y; double z; }
Next, there is a class that moves everything to their world position, which is now relative to the floating origin. The floating origin is a 64-bit coord starting at (0, 0, 0). The space is divided into blocks, for example 128x128x128. Whenever the focus leaves block (0, 0, 0), the floating origin is moved.
An example:
NOTE: I’m using w(…) for world space coordinates, which is transform.position. I’m using r(…) for real space coordinates, which are 64-bit.
floating origin = r(0, 0, 0)
focus world pos = w(127, 0, 5) (the focus is the player)
Now the player moves to w(129, 0, 5). This brings the focus block to (1, 0, 0). The floating origin manager will now do the following:
set its floating origin to r(128, 0, 0)
move the player, the camera, all the enemies and all the terrain tiles by w(-128, 0, 0). Which means they end up at realCoord - floatingOrigin.
Later, the player moves to w(129, 0, 5) again. This brings the focus block to (2, 0, 0) compared real space, or (1, 0, 0) compared to world space. The floating origin manager will now do the following:
set its floating origin to r(256, 0, 0)
move the player, the camera, all the enemies and all the terrain tiles by w(-128, 0, 0)
Some notes:
it matters when the floating origin manager’s update function executes
rigidbodies are a problem. You sometimes need to reset their inertia and it’s best to wait moving the floating origin until none of them are awake and colliding
world space particles and trails don’t work











