Interactive Physics Tool

Inverted Pendulum Simulator

Experiment in real-time with rotational inertia, angular damping, gravity, and simulated wind gusts. Learn the classical mechanical equations and computer graphics algorithms that make browser balance games feel intuitive yet relentlessly challenging.

Interactive Laboratory & Whitepaper · 1,400 words · Updated October 2026

Interactive Balance Sandbox

Use the simulator below to inspect how physical variables alter system stability. Adjust gravity, damping (air resistance), pillar length, and manual torque impulses to see how the spirit responds to dynamic disturbances.

The Classical Mechanics of Balance

At its scientific foundation, Wobbly Spirit models an inverted pendulum. In classical physics, a normal pendulum hangs downward from a pivot point, creating a stable equilibrium: whenever the bob is displaced from the vertical axis, gravitational force creates a restoring torque that pulls it back toward the center.

An inverted pendulum flips this system upside-down. The center of mass is situated above the pivot point. Because gravity pulls downward, any deviation from vertical creates an unstable torque that accelerates the displacement away from equilibrium. Without continuous, precise corrective input, the system diverges exponentially and falls.

τ_net = I · d²θ/dt² = m · g · (L / 2) · sin(θ) - γ · (dθ/dt) + τ_input + τ_wind

Where the variables denote:

  • θ (Theta): The angular displacement from vertical (measured in radians).
  • I: The rotational moment of inertia of the pillar about the base pivot ($I = \frac{1}{3} m L^2$).
  • m · g · (L / 2) · sin(θ): The gravitational overturning torque. As θ increases, the lever arm grows, producing non-linear runaway acceleration.
  • γ (Gamma): The aerodynamic rotational damping coefficient, resisting angular velocity.
  • τ_input: The active player counter-torque applied via keyboard arrow keys or touch pads.
  • τ_wind: Stochastic atmospheric force vectors introduced by crosswinds, bird impacts, and storm gusts.

Why Fixed 60Hz Delta-Time Is Critical

In browser-based game development, most developers rely on the native requestAnimationFrame(callback) method. However, modern consumer hardware displays run at wildly differing refresh rates:

  • Standard office monitors: 60 Hz (16.67 ms per frame)
  • Modern mobile smartphones: 90 Hz or 120 Hz (11.11 ms or 8.33 ms per frame)
  • Competitive gaming displays: 144 Hz, 165 Hz, or 240 Hz (6.94 ms to 4.16 ms per frame)

If physics updates are naively calculated per rendering frame without a fixed delta accumulator, the game accelerates uncontrollably on a 144 Hz display or experiences erratic numerical drift. A physics step that feels balanced on a standard laptop becomes virtually unplayable on a high-refresh monitor.

The Fixed Accumulator Architecture in Wobbly Spirit

To eliminate refresh rate disparity, Wobbly Spirit implements Glenn Fiedler’s canonical "Fix Your Timestep" architecture:

const FIXED_STEP = 1 / 60; // 0.016666s let accumulator = 0; let lastTimestamp = performance.now(); function gameLoop(now) { const dt = Math.min((now - lastTimestamp) / 1000, 0.1); // Clamp against spiral of death lastTimestamp = now; accumulator += dt; while (accumulator >= FIXED_STEP) { physicsStep(FIXED_STEP); // Pure deterministic step accumulator -= FIXED_STEP; } render(accumulator / FIXED_STEP); // Interpolate visual frame requestAnimationFrame(gameLoop); }

This guarantees that whether a user plays on an iPad running ProMotion at 120 Hz, an Android phone at 60 Hz, or an ultra-fast desktop monitor at 240 Hz, the physical pendulum moves through precisely identical mathematical equations at 60 ticks per second.

Human Control vs. PID Stabilization

Engineers stabilize inverted pendulums in robotics (such as Segways and rocket boosters during vertical landings) using PID (Proportional-Integral-Derivative) controllers:

  • Proportional (P): Applies force proportional to the current lean angle.
  • Derivative (D): Applies dampening proportional to the rate of fall, preventing overshoots.
  • Integral (I): Eliminates steady-state error caused by constant wind gusts.

In human gameplay, our visual cortex and motor reflexes act as an organic PID controller. Beginners often fail because they only react to the Proportional component (pushing when they see the spirit tilted). Advanced players naturally cultivate a Derivative instinct: they anticipate angular velocity and tap lightly in reverse before the pillar crosses vertical, preventing the dreaded pendulum oscillation bounce.

Apply the Science to the Game

Now that you understand the mathematical physics of momentum and damping, test your skills on the actual 30 levels of Wobbly Spirit.

▶ Launch Wobbly Spirit