Skip to content

concepts shifting origin

Tomáš Malý edited this page Jan 10, 2019 · 1 revision

Shifting Origin

Using Camera Objects or Collider probe requires the use of Map Make Local. This however limits the playable area to just some small surrounding area. Shifting origin makes the game playable again on the entire planet while still using the Map Make Local.

The trick is that the local area is shifted, following a selected object (eg. the player). The shift happens whenever the focused object moves further from world origin than a specified threshold. It will simultaneously rotate and move the planet and all Unity Game Objects in such a way, that current position of the focused object is moved to new origin, while maintaining relative position of the objects and the planet surface.

The shifting is accomplished by two scripts that work together.

  • Map Shifting Origin - this script is attached to the Map. It will check when the focused object reaches the threshold and will perform the shift.

  • Object Shifting Origin - this script is used to mark which Game Objects should be affected by the shift. The focused object must have this script attached.

The Object Shifting Origin script has two virtual methods that you may override.

  • OnBeforeOriginShift - this function is used to filter which objects are allowed to be shifted by which maps.

  • OnAfterOriginShift - this function is useful to perform any additional operations for things, that cannot be updated directly, such as updating internal state, updating unity particles, etc.

Note that the shift modifies both positions and rotations of objects.