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 by periodically moving the player back toward the center of the scene, and the position of everything else is adjusted to make it look as if nothing changed.

The two main components involved in the process are:

  • Floating Origin Manager: manages object repositioning to keep player near center.

  • Floating Origin Object: Added to every object that needs to be repositioned in the scene when the floating origin manager updates. Camera, vehicles, projectiles, missiles, environment objects, etc.

Floating Origin Manager

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

The Floating Origin Manager repositions objects in the scene when the player gets too far from center.
  • Focused Transform - the transform that will be positioned back at the center when it exceeds the 'Max Distance From Center'. Usually the camera, or the player vehicle.

  • Max Distance From Center - The max distance from the center that the 'Focused Transform' can get before it is moved back to the center.

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 Floating Origin Object component to the transform that you wish to be moved. You can parent many objects to a single transform and move them as one if the component is added to the root transform.

A Floating Origin Object is one that must be moved when the floating origin is updated.
  • Manage Trail Renderers - whether to manage trail renderers during a floating origin shift in such a way as to prevent stretching/visual glitches.

  • On Pre Origin Shift - Event called just before an origin shift. Can be used to save the state of something that would be negatively impacted by a sudden change in position.

  • On Post Origin Shift - Event called just after an origin shift. Can be used to restore the state of something if it has been impacted by an origin shift.

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, 'On Pre Origin Shift' and 'On Post Origin Shift' 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 'On Pre Origin Shift' and restore it in 'On Post Origin Shift' to prevent issues.