Avoiding Simulation Explosions: Keeping Game Physics Stable
Preventing Unstable Physics Simulations
Physics simulations are a core component of many video games, providing realistic interactions between game objects like particles, rigid bodies, and cloth. However, inaccuracies and errors can accumulate over time, leading to exponentially increasing forces and velocities in a runaway feedback loop known as a “simulation explosion.”
Simulation explosions manifest as objects unpredictably flying apart, oscillating violently, or passing through other objects. These visually disturbing glitches break the player’s immersion and realism of the simulation.
Fortunately, game developers have identified techniques to enhance the numerical stability of physics engines. By understanding common causes of instability, implementing force limits, using continuous collision detection, and controlling error with variable time steps, unstable simulations can be avoided.
Defining Simulation Explosions
The term “simulation explosion” refers to the rapid uncontrolled increase in motion energy and forces in a physics simulation over time. Specifically, it is when velocities, accelerations, or interaction forces grow exponentially during each time step iteration.
For example, a fast-moving object could pass partially through a wall due to inadequate collision detection. This interpenetration allows attractive and repulsive forces between the objects to greatly increase, causing violent explosions of motion. The kinetic energy introduced leads to even worse collisions afterward, resulting in a cascading instability.
The effects only get more extreme over time as small floating point errors accumulate. While real-world physics naturally dissipates energy through friction and damping, simulated systems continue growing exponentially chaotic. Soon objects vibrate, stretch, and fly apart at physically impossible speeds.
Key Attributes
- Unbounded increase in motion energy over time
- Exponential velocity/force growth each iteration
- Physically impossible/nonsensical object behavior
- Visually disturbing glitches and explosions
- Ruins plausibility and realism of simulation
Examples
Simulation explosions frequently occur when fast-moving rag dolls or cloth simulations penetrate static geometry. The engines attempt to resolve the invalid configuration but get trapped in a feedback loop of escalating forces.
Stacks of objects can also detonate as minor overlaps trigger repulsions that grow exponentially. A row of dominos may blast apart as if rigged with explosives if insufficient damping is applied.
Causes of Unstable Simulations
Several poor simulation practices contribute to allowing error accumulation and uncontrolled forces that fuel simulation explosions:
Excessive Forces
Allowing forces between particles, constraints, and collision contacts to grow without limit is a clear path to simulation explosions.
Repulsion, attraction, spring forces, and collisions apply impulses to alter momentum. If left unchecked, positive feedback loops can drive objects to extreme velocities.
Poor Collision Detection
Inadequate collision detection allows objects to partially penetrate at high velocities. Interpolation errors and missed fast collisions then allow forces to explode growth between penetrating bodies.
These sudden high forces cause velocity changes that worsen penetration leading to yet higher forces, quickly accumulating instability.
Numerical Error Accumulation
Round-off errors from continuous re-computation of velocities, positions, and forces slowly introduce inaccuracy. Such floating point inaccuracies detonate exponential growth if not controlled.
Chaotic motion allows more error build up. Precision loss gradually dominates until simulations become completely unstable and non-physical.
Managing Forces
Unconstrained forces are typically the direct enabler of unstable growth leading to simulation explosions. Game physics engines provide several techniques for limiting, damping, and directing forces.
Limiting Force Magnitudes
The most direct way to control extreme forces is to clamp the maximum value they can reach. Individual particle interactions, joints, collisions, and total force outputs can have ceiling limits set.
Capping the impulse strength prevents unchecked exponential growth while still allowing reasonable force exchange. Tuning appropriate thresholds requires testing and profiling during destabilizing scenarios.
Damping Oscillations
Real-world forces naturally dissipate energy through friction, deformation, and sound. Numerical simulation systems require explicit damping terms to avoid continued oscillations.
Linear and angular damping coefficients simulate energy loss mechanisms. They convert excessive kinetic motion into heat losses, steadying objects to stable non-exploding states.
Robust Collision Handling
Penetrations and intersections between objects generate extreme forces that can launch exponential instability. Refined collision handling techniques avoid such interpenetrations.
Continuous Collision Detection
Standard discrete collision detection tests for overlaps at fixed timestep intervals. Fast motions can skip past objects in a single time step.
Continuous collision detection traces trajectory sweeps during each step. Any generated collisions apply forces to prevent objects passing through each other.
Separating Fast-Moving Objects
When high speed collisions are detected, objects can be temporarily repositioned outside each other. This separation distributes forces over several small collisions rather than one extreme impulse.
After eliminating initial penetration, regular collisions can resume with the relative velocity capped to prevent further explosions.
Controlling Error
Floating point accuracy limitations gradually allow systemic error build-up. Controlling time integration and simulation precision constrains this emergence of non-physical behavior.
Variable Time Steps
Fixed duration time steps accumulate compounding errors from large numbers of iterations. Adapting the timestep duration based on activity levels localizes errors.
Smaller steps enhance precision during intense collisions and forces while longer steps maintain efficiency for stable configurations.
Resetting Simulations
Long-running simulations inevitably drift from their initial conditions due to compounding systemic inaccuracies. Periodic total resets eliminate accumulated errors.
Transient properties like position and velocity are re-initialized to ground truth values, preventing error cascades without losing permanent state like scores or object parameters.
Example Pseudo-Code for Stabilization Techniques
Applying force limits, continuous collision detection, damping, and adaptive time steps helps stabilize physics simulations. Pseudo-code examples demonstrate integrating stabilization best practices:
Force Limiter Function
float LimitForce(float rawForce, float maxForce) { float finalForce = rawForce; if(abs(rawForce) > maxForce) finalForce = Sign(rawForce) * maxForce; return finalForce; }
Continuous Collision Detection
bool CheckTrajectoryCollision(Object A, Object B, float dt) { // Interpolate motion over dt for(float t=0; t
Apply Linear Damping
void ApplyDampingForce(Object obj, float dampCoef) { // Scale down velocity float vel = obj.GetVelocity(); vel *= (1.0 - dampCoef); obj.SetVelocity(vel); }
Variable Timestep Integration
void IntegrateSimulation(float baseDT) { float dt = baseDT; if(ExplosionsLikely()) dt = 0.25*baseDT; // Smaller steps during complexity // Position update forEach(obj) obj.position += obj.velocity*dt; // Collision detection and force application // Velocity update forEach(obj) obj.velocity += netForces*dt; }
Strategically limiting forces, avoiding penetrations, damping oscillations, and adapting precision controls error growth - combining to stabilize simulations against explosions. profiles during destabilizing scenarios.