Floating Origin System

The floating origin system allows you to create large scenes in your game without experiencing camera and UI shaking caused by floating point precision issues.

The way that this is achieved is that the player ship and the camera are periodically moved back toward the center of the scene, and the position of everything else is adjusted to make it look as if nothing changed.

Floating Origin Manager

To set up a scene to use the floating origin, first add a FloatingOriginManager component anywhere in your scene. This is a singleton, so there must be only one of them in the scene at any time.

Next, set the 'Focused Transform' in the inspector of the Floating Origin Manager. This is the object that will be moved to (0,0,0) when the floating origin is updated. Typically, this will be the camera object. Note that the focused transform still requires a Floating Origin Object component (see below).

Finally, in the inspector of the Floating Origin Manager, you can set the maximum distance that the focused transform is allowed to get from the center before it is moved back.

Floating Origin Objects

A floating origin object is any object that will move during a floating origin position update. This includes the player vehicle, the camera, enemy vehicles, projectiles, missiles and all types of visible objects.

To make an object a Floating Origin Object, simply add a FloatingOriginObject component to the transform that you wish to be moved. You can parent many objects to a single transform and move them as one.

Managing Position Changes

When things are moved, sometimes it can result in visual glitches, or problems with any component that stores world-space position information each frame.

The Floating Origin Object component already has an option in the inspector to manage all Trail Renderers in its hierarchy, so you don't need to worry about stretching glitches.

If you need to manage anything during a transition, the Floating Origin Object component contains two functions, OnPreOriginShift and OnPostOriginShift which are called immediately before and after a floating origin update, respectively. There are also Unity events in the inspector for these events. You can store state information in OnPreOriginShift and restore it in OnPostOriginShift to prevent issues.