Class ShiftingOrigin
Prevents floating point precision errors by shifting all scene objects back toward world origin when the main camera exceeds the distance threshold.
Namespace: NWH.Common.ShiftingOrigin
Assembly: NWH.DWP2.dll
Syntax
public class ShiftingOrigin : MonoBehaviour
Remarks
As objects move far from world origin [0,0,0], floating point precision degrades causing physics jitter and rendering artifacts. ShiftingOrigin solves this by periodically moving all scene content back toward origin, keeping the player near [0,0,0] at all times.
The shift is transparent to gameplay - relative positions remain identical. Useful for open world games, flight simulators, or any scenario with large travel distances.
Only affects the current scene. For multi-scene setups, ensure one ShiftingOrigin instance per loaded scene set.
Fields
| Edit this page View SourceInstance
Declaration
public static ShiftingOrigin Instance
Field Value
| Type | Description |
|---|---|
| ShiftingOrigin |
distanceThreshold
Distance from world origin in meters that triggers an origin shift. Default 500m works well for most scenarios.
Declaration
public float distanceThreshold
Field Value
| Type | Description |
|---|---|
| float |
onAfterJump
Event invoked after the origin shift completes and physics is re-synced.
Declaration
public UnityEvent onAfterJump
Field Value
| Type | Description |
|---|---|
| UnityEvent |
onBeforeJump
Event invoked before the origin shift begins. Rigidbody sleep thresholds are temporarily disabled.
Declaration
public UnityEvent onBeforeJump
Field Value
| Type | Description |
|---|---|
| UnityEvent |
Properties
| Edit this page View SourceTotalOffset
Cumulative offset applied to all objects since scene start. Useful for tracking absolute world position despite origin shifts.
Declaration
public Vector3 TotalOffset { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
Methods
| Edit this page View SourceRefreshCaches()
Refreshes cached references to Rigidbodies and ParticleSystems. Call this if new physics objects or particle systems are added to the scene at runtime.
Declaration
public void RefreshCaches()