simple verlet physics by stuart allen (funkypear)

29
Simple Verlet Physics for Games Stuart Allen (aka FunkyPear)

Upload: mochimedia

Post on 13-Jan-2015

17.316 views

Category:

Documents


6 download

DESCRIPTION

Stuart Allen instructs how to utilize verlet physics for more elegant motion in games.

TRANSCRIPT

Page 1: Simple Verlet Physics by Stuart Allen (FunkyPear)

Simple Verlet Physics for Games

Stuart Allen(aka FunkyPear)

Page 2: Simple Verlet Physics by Stuart Allen (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

Page 3: Simple Verlet Physics by Stuart Allen (FunkyPear)

Euler Integration

Page 4: Simple Verlet Physics by Stuart Allen (FunkyPear)

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)

Page 5: Simple Verlet Physics by Stuart Allen (FunkyPear)

Verlet Integration

Page 6: Simple Verlet Physics by Stuart Allen (FunkyPear)

Demo 1

Euler & Verlet Particle Movement Demo

Page 7: Simple Verlet Physics by Stuart Allen (FunkyPear)

Constraints

Constraints ensure two particles stay a certain distance apart by moving them towards or away from each other

Page 8: Simple Verlet Physics by Stuart Allen (FunkyPear)

Demo 2

Particle Constraint Demo

Page 9: Simple Verlet Physics by Stuart Allen (FunkyPear)

Gravity & Other Forces

Forces applied directly to particle positions Gravity: y += 1

Verlet motion makes force persist (inertia)

Page 10: Simple Verlet Physics by Stuart Allen (FunkyPear)

Demo 3

Particle Constraint with Gravity Demo

Page 11: Simple Verlet Physics by Stuart Allen (FunkyPear)

Simple Four Step Verlet Engine

Step 1: Apply forces (gravity, wind, etc)

Step 2: Verlet update

Step 3: Constraints

Step 4: Collision Detection

Page 12: Simple Verlet Physics by Stuart Allen (FunkyPear)

Rope

Expanding from our last demo, rope can be simulated by having a chain of points connected in row with sticks

Page 13: Simple Verlet Physics by Stuart Allen (FunkyPear)

Demo 4

Multiple Constraints Rope Demo

Page 14: Simple Verlet Physics by Stuart Allen (FunkyPear)

Cloth

Cloth can be simulated by a grid of points that are connected to their neighbours

Page 15: Simple Verlet Physics by Stuart Allen (FunkyPear)

Demo 5

Rope Becomes Cloth Demo

Page 16: Simple Verlet Physics by Stuart Allen (FunkyPear)

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

Page 17: Simple Verlet Physics by Stuart Allen (FunkyPear)

Engine Upgrade: Fixed Points

Fixed points do not move – other end of stick does all the moving

Page 18: Simple Verlet Physics by Stuart Allen (FunkyPear)

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)

Page 19: Simple Verlet Physics by Stuart Allen (FunkyPear)

Structures & Towers

Page 20: Simple Verlet Physics by Stuart Allen (FunkyPear)

Demo 6

Towers Editor Demo

Page 21: Simple Verlet Physics by Stuart Allen (FunkyPear)

Demo 7

Game Jam Tower Game Demo

Page 22: Simple Verlet Physics by Stuart Allen (FunkyPear)

Similar Mechanic:World of Goo (2D Boy)

Page 23: Simple Verlet Physics by Stuart Allen (FunkyPear)

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

Page 24: Simple Verlet Physics by Stuart Allen (FunkyPear)

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

Page 25: Simple Verlet Physics by Stuart Allen (FunkyPear)

Demo 8

Blobs Editor Demo

Page 26: Simple Verlet Physics by Stuart Allen (FunkyPear)

Blobs – Each Point Linked to Opposite

Page 27: Simple Verlet Physics by Stuart Allen (FunkyPear)

Blobs – With Central Point

Page 28: Simple Verlet Physics by Stuart Allen (FunkyPear)

Similar Mechanic:Gish (Chronic Logic)

Page 29: Simple Verlet Physics by Stuart Allen (FunkyPear)

Thanks for listening! :)

More info and source code at

www.funkypear.com/mochilondon2012