Click to spawn · Right-click to remove · Space to pause
Gravity is modeled as a constant downward acceleration vector (g) applied to each ball's vertical velocity (vy) per time step:
vy = vy + g
When a ball hits a boundary, it reflects its velocity vector. The coefficient of restitution (e) determines the percentage of kinetic energy retained. A bounce value of 0.75 means it keeps 75% of its speed, losing 25% to deformation and heat.
Real-world mass scales with volume (3D sphere). In this engine, mass (m) is calculated using the ball's radius (r) and density (d):
This cubic relation means doubling a ball's size increases its mass by 8x! Denser balls possess significantly higher momentum, easily pushing lighter balls aside.
Collisions are resolved in two phases: