In an open-world game, why does the player's character model visibly shake 20 kilometres from the world origin, and how does origin rebasing fix it?
answer
- spacing between floats grows with distance
- about 2 mm at 20 km
- subtracting two huge positions
- move the world, not the player
- keep a high-precision global offset
basics
~20 sSingle-precision positions near 20,000 m snap to a grid about 2 mm wide, so vertices, bones and contacts jump between grid points. Origin rebasing periodically shifts the whole world so the player stays near zero, where the grid is fine.
solid answer
~50 sA single-precision float keeps 24 significant bits, so the spacing between representable values doubles with each power of two: about `1.2e-7` m near 1 m but `2^-9`, about 2 mm, between 16,384 and 32,768 m. At 20 km every world position is quantised to that grid. Transforming a vertex to view space subtracts the camera position from the object's, two numbers near 20,000, so the result keeps only 2 mm resolution, and a camera a metre away magnifies that into visible shaking; the same grid makes skinned bones, physics contacts and slow movement stutter. **Origin rebasing** moves the origin: when the player passes a threshold distance, subtract one offset from every object's position, physics body and cached spatial structure in a single frame, and keep the accumulated offset in a double or integer cell so saves, streaming and networking still know true world positions.
code
pseudocode · 10 lines// single precision, world units are metres
position = 20000.0
step = 0.0008 // 0.8 mm this frame
position = position + step // gap near 20,000 is 0.00195; 0.0008 is under half of it
// position is still exactly 20000.0: the movement was rounded away
position = 20000.0
step = 0.0012
position = position + step // rounds to the next float, 20000.001953125
// the object moved 1.95 mm, not 1.2 mmgo deeper
Recall that floats keep a fixed number of significant bits, so the gap between representable positions grows the farther you are from the world origin.
Work out the spacing at a given distance, 2^(e-23) in single precision, and explain how subtracting camera and object positions exposes it as visible jitter.
Diagnose by symptom and distance, then list everything a rebase must shift: physics bodies, spatial indexes, particles, previous-frame data and audio, plus how saves and networking keep global positions.
Weigh rebasing against camera-relative rendering, double-precision world positions and sector coordinates for the world size, multiplayer model, tool chain and memory budget the project actually has.
## Why precision falls with distance A floating-point number stores a fixed number of significant bits and an exponent. The spacing between neighbouring representable values, one **ULP** (unit in the last place), is `2^(e - 23)` in single precision for any value between `2^e` and `2^(e+1)`. Precision is roughly constant **relative** to the magnitude, so in **absolute** world units it gets coarser the farther you are from zero: | distance from origin | single-precision spacing | double-precision spacing | |---|---|---| | 1 m | about 1.2e-7 m | about 2.2e-16 m | | 1 km | about 6.1e-5 m (0.06 mm) | about 1.1e-13 m | | 20 km | about 0.00195 m (2 mm) | about 3.6e-12 m | | 100 km | about 0.0078 m (8 mm) | about 1.5e-11 m | At 20 km a single-precision position can only take values on a grid about 2 mm wide. That sounds small, until the camera is close. ## Where the shaking comes from Several systems quantise to that grid at once, which is why the symptom looks like general wobble rather than one bug: - **Vertex transforms.** A mesh's vertices are stored relative to its own origin and are precise. Multiplying by the object's model-to-world matrix adds a translation near 20,000, rounding every world-space vertex to the 2 mm grid; the view transform then subtracts the camera's position, also near 20,000. The difference is small but carries only 2 mm resolution, and each vertex rounds differently from frame to frame as the character moves. - **Magnification.** With a 60-degree vertical field of view on a 1080-line screen, a camera one metre away shows about 935 pixels per metre, so a 2 mm error is about two pixels: easily visible on a face or a weapon in first person. (These are a scenario's figures; the point is that close cameras magnify world-space error.) - **Skinned animation.** Bones posed in world space snap independently, so limbs vibrate relative to each other. - **Physics and movement.** A position update `p = p + v * dt` is lost entirely when the step is under half the spacing: at 20 km, a step below about 1 mm rounds back to the old position, so slow creep stalls and faster motion advances in uneven 2 mm jumps. Contacts resolved at millimetre scale flicker. **Diagnosis:** the symptom grows with distance from the origin and roughly doubles each time the distance crosses a power of two. Teleporting a test character to 1 km, 10 km and 50 km and watching the amplitude change confirms it in minutes. ## Origin rebasing Origin rebasing, also called a **floating origin**, keeps the player near zero by moving the world instead: 1. Track the player's or camera's distance from the current origin each frame. 2. When it exceeds a threshold (a few kilometres in a typical scenario), pick a new origin near the player, often snapped to a grid so offsets are round numbers. 3. Between simulation steps, subtract the shift from every positioned thing: objects, physics bodies, particle systems, navigation data, audio emitters, and anything holding last frame's positions or matrices for motion vectors or temporal effects. 4. Add the shift to an **authoritative origin offset** kept in double precision or as an integer cell index, so that global position = offset + local position for saving, streaming and networking. ``` const REBASE_DISTANCE = 4000.0 // scenario threshold in metres const SNAP = 1000.0 function maybeRebase(world): p = world.player.localPosition // single precision, relative to current origin if length(p) < REBASE_DISTANCE: return shift = roundToMultiple(p, SNAP) // whole kilometres world.originOffset += toDouble(shift) // authoritative, double precision for each obj in world.positionedObjects: obj.localPosition -= shift world.physics.translateAllBodies(-shift) world.spatialIndex.rebuild() ``` Pitfalls a rebase must handle: - **Cached spatial data** (broad-phase structures, spatial hashes) must be shifted or rebuilt, or queries return stale cells. - **A hitch** when thousands of objects move in one frame; parenting streamed cells under a few root transforms makes the shift cheap. - **Multiplayer**: each client has its own origin, so messages carry global coordinates, and a server simulating everyone cannot keep one origin near every player. ## Alternatives and how they compare | approach | how it works | what it costs | |---|---|---| | origin rebasing | shift the world so the player stays near zero | every system holding positions must cooperate | | camera-relative rendering | subtract the camera position in double on the CPU, send small floats to the GPU | fixes rendering only; simulation is still far from zero | | double-precision world positions | store and simulate positions as doubles | twice the memory per position, half the SIMD width, still converted to float for rendering | | sector coordinates | integer cell index plus a float offset inside the cell | arithmetic across cell borders needs care | Many large-world engines combine them: doubles or cells for authoritative positions, camera-relative floats for rendering, and local floats inside each physics region.
- Why does a slowly moving object far from the origin stall rather than just render shakily?A position update adds a small displacement to a large coordinate. If the displacement is under half the spacing between floats there, about 1 mm at 20 km in single precision, the sum rounds back to the old position. Slow creep is lost and slightly faster motion advances in uneven grid-sized jumps, so the simulation itself is wrong, not only the picture.
- Why is switching the whole engine to double precision not a free fix?Doubles double the memory and bandwidth of every position and halve how many values fit in a SIMD register, and consumer GPUs run double-precision math at a small fraction of their float rate. Rendering therefore still converts to float, usually camera-relative. Engines that support large worlds tend to keep doubles for authoritative positions and floats for local work.
- What breaks if a rebase forgets last frame's transforms?Anything comparing this frame with the last sees the whole shift as motion: per-pixel motion vectors, temporal anti-aliasing history, motion blur and velocity estimated from position differences. For one frame every object appears to move by kilometres, producing a smear or a physics impulse. Shift the stored previous-frame positions and matrices by the same offset.
- Float precision only becomes a problem millions of units from the origin.
- The jitter is purely a rendering bug; physics and animation are unaffected.
- Rebasing means teleporting the player to zero while the world stays put.
- Scaling the whole world down by 100 removes the precision problem.
- The fix is to store every mesh's vertices in double precision.