Rally Cross physics: An Analysis 10 Years Later
Download
Report
Transcript Rally Cross physics: An Analysis 10 Years Later
Rally Cross physics:
An Analysis 10 Years Later
Jim Buck
Twitchy Thumbs Entertainment, Inc.
[email protected]
May 31, 2007
Who is this dude??
•
•
•
•
1996 – 2000 : 989 Studios, programmer
2000 – 2003 : DepthQ, founder
2003 – 2005 : SCEA, programmer
2005 – present : Twitchy Thumbs, founder
Why?
• Learn what worked (big picture)
• Tricks of the past (small picture)
• Spare cycles (hah!) on next gen
“Doing a lot with a little is something
we can't forget how to do.”
– Mike Acton, Insomniac Studios
What is Rally Cross?
What is Rally Cross?
•
•
•
•
PS1 off-road racing game
Feb ‘97 in North America
Sony-developed/published
200,000 sell-through N.A.
• Japanese/PAL releases
• Considered “cult” classic
• One of first for PS1-on-PSP
What is Rally Cross?
Pre-demo
Rally Cross physics history
• Chris Hecker physics articles too late (Oct
96 - Jun 97)
• SGI 4dgifts buttonfly visualizer demo
• Robert Sheehan’s bouncer simulation
Physics Primer
• F = m*a
• v += a*t = (F/m)*t
• p += v*t
All math is 1.19.12 fixed-point!
What is Rally Cross physics?
Springs!
(well, actually, damped springs)
Damped spring physics
v0
t=0
Spring at rest
v1
t=1
x
F = – k*x – c*v1
Hooke’s law
Rally Cross physics components
•
•
•
•
•
Vehicle box
Box interaction with ground
Box interaction with track boundaries
Box interaction with another box (vehicle)
Vehicle-specific physics
Vehicle 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
Vehicle Box
Vehicle Box
For each spring:
• x = length(p1 – p0) - at_rest_length
• v = dot(v1 – v0, unit(p1 – p0))
• F = (– k*x – c*v) * unit(p1 – p0)
• F1 += F, F0 += –F
v1
v0
p0
p1
Vehicle 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
Box Interaction with Ground
• Ground is a height-mapped grid
• Gravity constantly affects point masses:
F = m*G
Box Interaction 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 = (– k*xn – c*vn) * normal_map(p.x, p.z)
• Formula is for a damped spring!
n
x
height_map
xn
p
v
vn
Sidebar: Friction
• Static: Fmax = fs*N
• Kinetic: F = fk*N
v=0
v
F
N
m*G
fs*N
N
m*G
fk*N
Box Interaction with Ground
Friction
• Viscous: F = –fv*vo
• Static/kinetic
– If vo == 0
• If Fo <= fs*xn, Fo = 0
• Else Fo –= fk*xn
– Else if length(vo + (Fo/m)*t) <= (fk*xn)*t, vo = 0
– Else F = –unit(vo) * fk*xn
Box Interaction 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
v
vn
Box Interaction with Another Box
• Sphere test for each car pair
• If succeeds, ray-through-box test
F = (– k*x – c*vn) * normal
(Formula look familiar?)
x
Box Interaction with Another Box
• If ray-through-box fails, test each car’s
points against other’s box
x
n
Again, F = (– k*x – c*vn) * normal
Vehicle-specific Physics
• For steering, F = –kv*vx (viscous friction!)
• For acceleration in Z, that’s a whole
‘nother presentation
X
X
Z
Z
But briefly…
engine axle
gear ratio
wheel axle
fs*N or fk*N
Physics Rendering
• Points time-stepped: v += (F/m)*t, p += v*t
• Display matrix:
X
Top face
Z
• Car position = top_center – box_height
• Wheel position = based on shock length
Physics Demo
Problems
• Box freaking out
• Stuck on track boundaries
Box Freaking Out
• Check “crossbars” dot product is in safe
range
• Check upper points are “above” lower
Lower points
points
+
Upper points
= bad!
Stuck on Track Boundaries
• Stuck if 2 adjacent points such that:
dot(n0b, n1b) < 0
• Find boundary intersected by center of box
to center of the 2 points
• Push out with spring equation
Optimizations
•
•
•
•
•
Constants mostly power-of-2
Pre-calcs (ex. 1/mass * time)
Cached and local pointers
64-bit MIPS mults
Assembly language for key math functions
and height-map lookup
Evolution of Physics
• CART World Series
– correct friction model on wheels
• Twisted Metal 3
– height-map gone
– collision with 3d geometry with no penetration
• Twisted Metal 4
– car-to-car collision using CSG
– better graphics
Q&A