Floating origin to handle large worlds in Unity. The article describes a Unity script called `FloatingOrigin.cs` that prevents precision errors in large game worlds by shifting the scene's origin when a reference object moves beyond a set distance threshold. The script can update all open scenes or just the active one, and it also adjusts the positions of particle systems, trail renderers, and line renderers to maintain visual consistency during the shift. FloatingOrigin.cs This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters // Based on the Unity Wiki FloatingOrigin script by Peter Stirling // URL: http://wiki.unity3d.com/index.php/Floating Origin using UnityEngine; using UnityEngine.SceneManagement; public class FloatingOrigin : MonoBehaviour { Tooltip "Point of reference from which to check the distance to origin." public Transform ReferenceObject = null; Tooltip "Distance from the origin the reference object must be in order to trigger an origin shift." public float Threshold = 5000f; Header "Options" Tooltip "When true, origin shifts are considered only from the horizontal distance to orign." public bool Use2DDistance = false; Tooltip "When true, updates ALL open scenes. When false, updates only the active scene." public bool UpdateAllScenes = true; Tooltip "Should ParticleSystems be moved with an origin shift." public bool UpdateParticles = true; Tooltip "Should TrailRenderers be moved with an origin shift." public bool UpdateTrailRenderers = true; Tooltip "Should LineRenderers be moved with an origin shift." public bool UpdateLineRenderers = true; private ParticleSystem.Particle parts = null; void LateUpdate { if ReferenceObject == null return; Vector3 referencePosition = ReferenceObject.position; if Use2DDistance referencePosition.y = 0f; if referencePosition.magnitude Threshold { MoveRootTransforms referencePosition ; if UpdateParticles MoveParticles referencePosition ; if UpdateTrailRenderers MoveTrailRenderers referencePosition ; if UpdateLineRenderers MoveLineRenderers referencePosition ; } } private void MoveRootTransforms Vector3 offset { if UpdateAllScenes { for int z = 0; z < SceneManager.sceneCount; z++ { foreach GameObject g in SceneManager.GetSceneAt z .GetRootGameObjects g.transform.position -= offset; } } else { foreach GameObject g in SceneManager.GetActiveScene .GetRootGameObjects g.transform.position -= offset; } } private void MoveTrailRenderers Vector3 offset { var trails = FindObjectsOfType