Simple Verlet Physics for Games
Stuart Allen(aka FunkyPear)
Euler Integration
Simplest method of moving particles and objects Need to keep track of object position and speed Each frame/time step add speed to position:
X = X + speedX
Y = Y + speedY
Euler Integration
Verlet Integration
Also fairly simple, but expandable to be more accurate (outside scope of this talk)
Need to keep track of object current position and previous position
Each frame/time step, calculate distance travelled since last time, and add to current position:
X = X + (X - oldX)
Y = Y + (Y - oldY)
Verlet Integration
Demo 1
Euler & Verlet Particle Movement Demo
Constraints
Constraints ensure two particles stay a certain distance apart by moving them towards or away from each other
Demo 2
Particle Constraint Demo
Gravity & Other Forces
Forces applied directly to particle positions Gravity: y += 1
Verlet motion makes force persist (inertia)
Demo 3
Particle Constraint with Gravity Demo
Simple Four Step Verlet Engine
Step 1: Apply forces (gravity, wind, etc)
Step 2: Verlet update
Step 3: Constraints
Step 4: Collision Detection
Rope
Expanding from our last demo, rope can be simulated by having a chain of points connected in row with sticks
Demo 4
Multiple Constraints Rope Demo
Cloth
Cloth can be simulated by a grid of points that are connected to their neighbours
Demo 5
Rope Becomes Cloth Demo
Relaxation
Loop over constrain step multiple time to pull points together and make final result more rigid
Less constrain loops means a more bendy and bouncy structure
Engine Upgrade: Fixed Points
Fixed points do not move – other end of stick does all the moving
Structures & Towers
Adding fixed points allows us to build fixed but flexible structures
Towers (fixed points on ground) Bridges (fixed points on either edge of a gap) Dangling ropes (fixed point above rope)
Structures & Towers
Demo 6
Towers Editor Demo
Demo 7
Game Jam Tower Game Demo
Similar Mechanic:World of Goo (2D Boy)
Engine Upgrade: Stick Length Tolerance
Sticks previously had set length Modify sticks to have min and max lengths. Soft body dynamics possible due to addition valid
solutions
Blobs
Blobs attempt to mimic gooey / gelatinous objects
Multiple different configurations: Centre point makes blob seem more solid Double skinning helps stop edge points glitching More tolerance in inner sticks makes for a flatter,
more dynamic blob
Demo 8
Blobs Editor Demo
Blobs – Each Point Linked to Opposite
Blobs – With Central Point
Similar Mechanic:Gish (Chronic Logic)
Thanks for listening! :)
More info and source code at
www.funkypear.com/mochilondon2012