Two Clocks, One Rope
Building an iPad runner with a 9-year-old child as Lead Designer and QA. The new reality of instant creation.
The physics engine in our iPad game completely shattered. A swinging rope, meant to be a core traversal mechanic, violently tore itself apart on screen. It wasn’t a bad physics formula; it was a temporal conflict. The rope was simultaneously bound to two different physics clocks.
When you mix UI animation loops with rigid-body physics engines, time becomes your biggest enemy.
The Temporal Rift
In DOOOORS, the rendering pipeline was driven by the standard requestAnimationFrame, pushing updates at 60 or 120 frames per second depending on the iPad’s display. However, we had wired the physics simulation to a fixed setInterval to ensure deterministic calculations regardless of frame drops.
We had created a temporal rift. The rope’s visual joints were being updated by the rendering clock, but the constraints holding the joints together were being enforced by the physics clock.
When the two clocks drifted out of phase by even a few milliseconds, the renderer would draw the rope joints further apart than the physics constraints allowed. In the next tick, the physics engine would panic, apply massive restorative forces to snap the rope back together, and launch the player into the stratosphere.
Single Source of Truth
A system cannot serve two masters. We had to completely rethink the pipeline.
We threw away the independent setInterval. We tied the physics engine directly into the requestAnimationFrame loop, but with a crucial decoupling: a fixed-timestep accumulator.
The renderer controls the single clock. But before it draws a frame, it passes the exact elapsed time to the physics engine. The physics engine then runs its deterministic simulation in fixed steps to “catch up” to the visual reality.
If your visual state and your mathematical state disagree on what time it is, the math will always violently correct the visuals. Pick one clock.
Next in the DOOOORS series: what it means when the barrier to building software drops to zero in the final article, The New Reality of Creation.