Title: OffRoad Racing Physics,
1Off-Road Racing Physics,
Jim Buck Twitchy Thumbs Entertainment,
Inc. jbuck_at_twitchythumbs.com August 19, 2009
2Who is this dude??
- 1996 2000 989 Studios, programmer
- 2000 2003 DepthQ, founder
- 2003 2005 SCEA, programmer
- 2005 present Twitchy Thumbs, founder
3Why?
- Yesterdays next-gen technology is todays
- achievability by indie developers
- handheld technology
- next-gen effects during spare CPU time
Doing a lot with a little is something we can't
forget how to do.
Mike Acton, Insomniac Studios
4What is Rally Cross?
5What is Rally Cross?
- PlayStation off-road racing
- Sony-developed/published
- February 97 in N. America
- 200,000 sold in N. America
- Japanese/PAL releases
- Considered cult classic
- One of first for PS1-on-PSP
6What is Rally Cross?
7Rally Cross physics history
- Chris Hecker physics articles too late (October
1996 - June 1997) - SGI 4Dgifts newton demo
- Robert Sheehans bouncer simulation
8Physics Primer
All math is 1.19.12 fixed-point!
9What is Rally Cross physics?
Springs!
(well, actually, damped springs)
10Damped spring physics
v0
t 0
Spring at rest
v1
t 1
x
F kx cv1
Hookes law
11Rally Cross physics components
- Vehicle box
- Box collision with ground
- Box collision with track boundaries
- Box collision with another box (vehicle)
- Vehicle-specific physics
12Vehicle Box
- 8 points, or point masses, representing box
corners - Each point accumulates forces (F) and gets
time-stepped at bottom of loop - 28 damped springs from each point to every other
point
13Vehicle Box
14Vehicle Box
- For each spring
- x length(p1 p0) - at_rest_length
- v dot(v1 v0, unit(p1 p0))
- F ( kx cv) unit(p1 p0)
- F1 F, F0 F
v1
v0
p1
p0
15Vehicle Box
- Shock springs are special
- Separated into Y and ortho-Y vectors
- Softer in Y than in ortho-Y
- Ortho-Y treated same as other springs
16Box Collision with Ground
- Ground is a height-mapped grid
- Gravity constantly affects point masses
- F mG
m
G
17Box Collision with Ground
- For each point mass, if under height-map
- xn (height_map(p.x, p.z) p.y)
normal_map(p.x, p.z).y - vn dot(v, normal_map(p.x, p.z)
- F ( kxn cvn) normal_map(p.x, p.z)
- Formula is for a damped spring!
n
xn
x
height_map
p
vn
v
18Sidebar Friction
- Static Fmax fsN
- Kinetic F fkN
v 0
v
N
N
F
fsN
fkN
mG
mG
19Box Collision with Ground
- Friction
- Viscous F fvvo
- Static/kinetic
- If vo 0
- If Fo lt fsxn, Fo 0
- Else Fo fkxn
- Else if length(vo (Fo/m)t) lt (fkxn)t, vo
0 - Else F unit(vo) fkxn
20Box Collision with Boundaries
- 2d (infinite height) line segments surrounding
the track - Physics is same as for hitting the ground
- Damped spring pushing back along normal
- Friction applied ortho to the normal
n
In bounds
xn
Out of bounds
p
vn
v
21Box Collision with Another Box
- Sphere test for each car pair
- If succeeds, ray-through-box test
F ( kx cvn) normal
(Formula look familiar?)
x
22Box Collision with Another Box
- If ray-through-box fails, test each cars points
against others box
x
n
Again, F ( kx cvn) normal
23Vehicle-specific Physics
- For steering, F kvvx (viscous friction!)
- For acceleration in Z, that would require a
separate presentation ?
X
X
Z
Z
24But briefly
engine axle
gear ratio
wheel axle
fsN or fkN
25Physics ? Rendering
- Points time-stepped v (F/m)t, p vt
- Display matrix
- Car position top_center box_height
- Wheel position based on shock length
X
Top face
Z
26Physics Demo
27Problems
- Box freaking out
- Stuck on track boundaries
28Box Freaking Out
- Check crossbars dot product is in safe range
- Check upper points are above lower points
Lower points
Upper points
bad!
29Stuck on Track Boundaries
- Stuck if 2 adjacent points such that dot(n0b,
n1b) lt 0 - Find boundary intersected by center of box to
center of the 2 points - Push out with spring equation
30Optimizations
- Constants mostly power-of-2
- Cached calculations (ex. 1/mass time)
- Local variables to avoid aliasing
- 64-bit MIPS multiplications
- Assembly language for key math functions and
height-map lookup
31Evolution of Physics
- CART World Series
- correct wheel friction
- Twisted Metal 3
- 3d poly collision with no penetration (no
height-map)
- Twisted Metal 4
- car-to-car collision with 3d boolean intersection
32QA
Contact jbuck_at_twitchythumbs.com