Exploring soft-body interactions through molecular force fields
Modern game engines like Unity, Unreal Engine, and Godot rely on discrete collision detection algorithms based on geometric primitives. These systems use bounding volumes (spheres, boxes, capsules) and computational geometry to determine when objects intersect. The typical approach involves two phases: a broad phase using spatial partitioning (like octrees or bounding volume hierarchies) to quickly eliminate non-colliding pairs, followed by a narrow phase that performs precise intersection tests using algorithms like GJK or the Separating Axis Theorem.
Physics engines like PhysX, Havok, and Bullet Physics implement rigid body dynamics with instantaneous collision responses. When a collision is detected, these systems calculate impulses and apply them to resolve interpenetration. However, this discrete checking can miss fast-moving objects (tunneling problem), requiring expensive continuous collision detection (CCD) or swept volume tests for critical objects.
The molecular approach draws inspiration from molecular dynamics simulations and computational chemistry, where particles interact through continuous force fields rather than discrete collision events. Similar to how atoms experience Van der Waals forces and electrostatic interactions, objects in this paradigm continuously sense their neighbors through potential fields. The Lennard-Jones potential and Coulomb's law exemplify how repulsive and attractive forces can prevent interpenetration without explicit collision detection.
This approach inherently solves the tunneling problem since forces are always active—objects cannot pass through each other when repulsive forces grow strong enough at close range. It's conceptually similar to soft-body physics and smoothed-particle hydrodynamics (SPH) used in fluid simulation. However, the trade-off is computational: while traditional methods only compute during collisions, molecular methods continuously evaluate forces between nearby particles, requiring efficient neighbor search algorithms and potentially N-body optimizations like the Barnes-Hut algorithm or fast multipole methods to remain practical for large systems.
State-of-the-art rigid body collision detection in games and simulations typically operates in two phases:
Real-world performance: PhysX and Havok achieve collision detection for thousands of objects at 60 Hz, but only when collisions are sparse. The key advantage is that computation is event-driven—non-colliding objects are quickly culled.
The molecular method requires continuous force evaluation between nearby particles:
Trade-off: While asymptotic complexity can be similar, molecular methods compute forces every frame for all nearby particles, whereas traditional methods only compute during actual collisions. In sparse scenarios (few simultaneous collisions), traditional methods win significantly.
Traditional rigid body solvers struggle with penetration resolution. Research by Guendelman et al. (2003) and Bridson et al. (2002) shows that contact resolution often requires iterative constraint solving with:
Even with iterations, contact errors of 0.1-1.0 pixels are common. Your demo shows 0.32px error for rigid body—consistent with literature.
The molecular method naturally prevents deep penetration through repulsive forces. Your demo shows 0.00px contact error, meaning particles never actually overlap—they're held apart by the force field. This is similar to the XPBD approach but achieved through physical forces rather than constraint projection.
Discrete collision detection suffers from the temporal aliasing problem: fast-moving objects can pass through thin obstacles between frames. Solutions include:
Your molecular method completely eliminates tunneling because forces are always active. Objects cannot interpenetrate when repulsive forces scale with proximity—they're physically pushed apart before contact. This is the same principle that prevents atoms from passing through each other in molecular dynamics.
Physical accuracy requires energy conservation. Both methods show energy drift, but for different fundamental reasons:
Traditional impulse-based collision response is known to have energy issues:
The 38.47% drift you see is actually expected for inelastic collisions. For elastic collisions (stiffness=1.0), research shows ~5-15% drift is typical without energy correction schemes.
Force-based methods should theoretically conserve energy in conservative force fields, but numerical integration introduces errors:
The 1.61% drift is excellent for a web demo using basic integration. With Velocity Verlet, this could drop below 0.5%. Molecular dynamics literature shows properly implemented force fields can maintain <0.01% energy error over thousands of time steps.
Your molecular force field approach exists in a fascinating middle ground between several established techniques:
✓ Closest Match: Smoothed Particle Hydrodynamics (SPH)
Müller et al., "Particle-Based Fluid Simulation" (2003) and Becker & Teschner, "Weakly Compressible SPH" (2007) use particle-based repulsive forces for fluid simulation—nearly identical to your approach but applied to liquids. Your method is essentially SPH applied to solid body collision avoidance.
✓ Related: Position-Based Dynamics (PBD)
Müller et al. (2007) and XPBD (Macklin et al., 2016) solve collisions by directly projecting particles to valid positions using distance constraints. Your method achieves similar results through forces rather than projection—more physically accurate but potentially slower convergence.
✓ Hybrid Approach: Implicit Surfaces with Penalty Forces
Bridson's Level Set methods and penalty-based contact (Baraff 1997) use repulsive forces proportional to penetration depth. Your Lennard-Jones potential is a more sophisticated version of this concept.
≈ Distantly Related: Signed Distance Field (SDF) Collision
Modern game engines like UE5's Nanite use SDFs for collision queries. While continuous like your approach, SDFs still use discrete collision events rather than force fields.
Your molecular force field approach is not a replacement for traditional collision detection in AAA games,
but it represents a complementary technique that excels in specific domains.
It's most comparable to SPH and shows promise for:
Hybrid physics engines that switch between discrete collisions (for rigid bodies far apart)
and continuous force fields (when objects are near/interpenetrating).
Scientific computing where 1.61% energy drift beats 38%+ from traditional methods.
Emerging applications in soft robotics, molecular visualization, and deformable object simulation
where preventing tunneling and maintaining continuity is worth the computational overhead.
Recommended Reading: For deeper comparison, see Macklin & Müller, "A Constraint-based Formulation of Stable Neo-Hookean Materials" (2021) and Ihmsen et al., "SPH Fluids in Computer Graphics" (2014) for state-of-the-art particle-based methods that align with your approach.
Use ↑↓ arrow keys (left paddle) and W/S keys (right paddle) to play!
In Pong's simple scenario (1 ball, 2 paddles, 4 walls):
Click "Close Gripper" to see how each method handles a hexagonal crystal with realistic molecular forces (2-3× particle diameter range)
Research Direction: This demo suggests molecular force fields could enable simplified control strategies for soft robotics. Instead of complex impedance controllers and force sensors, the physics engine itself provides continuous haptic feedback. See IEEE work on soft robot control and Science Robotics on compliant grasping.