Shifting Origin

A simple shifting origin script. Moves all objects in the scene to keep the player near the origin once the distance exceeds the Distance Threshold.

Shifting origin is a commonly used technology in most open-world games to combat the degradation of the quality of physics and visuals far from the origin (~1000 units or more). Since Unity uses floats for storing position data the largest value that can be stored is 7 digits. When the distance is large only a limited number of the digits is available on the right side of the decimal point. That means that at ~100km from the origin the position resolution is only 1cm! By moving the object back to [0, 0, 0] each time that the object gets too far away from the origin, and also moving the whole world with it for the same amount, an illusion of travelling great distances is formed while the player never gets further than some threshold from the origin.