Material Type: Notes;
Professor: Laird;
Class: Comp Game Design;
Subject: Electrical Engineering And Computer Science;
University: University of Michigan - Ann Arbor;
Term: Unknown 1989;
Download Basic Game Physics - Computer Game Design - Lecture Slides | EECS 494 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!
Basic Game Physics
John E. Laird and Sugih Jamin
Based on The Physics of the Game, Chapter 13 of Teach
Yourself Game Programming in 21 Days,
pp. 681-
Why Physics?
Some games don’t need any physics
Games based on the real world should look realistic,
meaning realistic action and reaction
More complex games need more physics:
sliding through a turn in a racecar, sports games, flight simulation, etc.
Running and jumping off the edge of a cliff
Two types of physics:
Elastic, rigid-body physics, F = ma , e.g., pong
Non-elastic, physics with deformation: clothes, pony tails, a whip, chain, hair, volcanoes, liquid, boomerang
Elastic physics is easier to get right
Position and Velocity
Modeling the movement of objects with velocity
Where is an object at any time t?
Assume distance unit is in pixels
Position at time t for an object moving at velocity
v , from starting position x
0
x(t) = x0+ vxt
y(t) = y0+ vyt
Incremental computation per frame, assuming
constant time step and no acceleration:
vx and vy constants, pre-compute
x += vx, y += vyvy vx ( x 0 , y 0 ) v : velocity
Acceleration
Acceleration ( a ): change in velocity per unit time Acceleration Velocity Approximate
Gravity
Gravity is a force between two objects:
Force F = G (m1m2
)/ D
2
G = 6.67 x 10-11^ Nm^2 kg-
mi : the mass of the two objects
D = distance between the two objects
So both objects have same force applied to them
F=ma --> a=F/m
On earth, assume mass of earth is so large it doesn’t
move, and D is constant
Assume uniform acceleration
Position of falling object at time t :
x(t) = x 0
y(t) = y 0 + 1/2 * 9.8 m/s^2 * t^2
Incrementally, y += gravity (normalized to frame rate)
Space Game Physics
Gravity
Influences both bodies
Can have two bodies orbit each other
Only significant for large mass objects
Consider N -body problem
What happens after you apply a force to an object?
What happens when you shoot a missile from a
moving object?
What types of controls do you expect to have on a
space ship?
What about a flying game?
Friction
Conversion of kinetic energy into heat
Frictional force Ffriction
= m g μ
m = mass, g = 9.8 m/s2 ,
μ = frictional coefficient = amount of force to maintain a constant speed
F actual
= F
push
- F
friction
Careful that friction doesn’t cause your object to move backward!
Consider inclined plane
Usually two frictional forces
Static friction when at rest (velocity = 0). No movement unless overcome.
Kinetic friction when moving ( μ k < μ s ) mass( m ) m*g μ Fpush Ffriction
Race Game Physics
Non-linear acceleration
Resting friction > rolling friction
Rolling friction < sliding friction
Centripetal force?
What controls do you expect to have for a racing game?
Turning requires forward motion!
What about other types of racing games
Boat?
Hovercraft?
Particle System Explosions
Start with lots of point objects (1-4 pixels)
Initialize with random velocities based on velocity of
object exploding
Apply gravity
Transform color intensity as a function of time
Destroy objects upon collision or after fixed time
Can add vapor trail (different color, lifetime, wind)
Advanced Physics
Modeling liquid ( Shrek,
Finding Nemo )
Movement of clothing
Movement of hair
( Monster Inc .)
Fire/Explosion effects
Reverse Kinematics
Back to Collisions
Steps of analysis for different types of collisions
Circle/sphere against a fixed, flat object
Two circles/spheres
Rigid bodies
Deformable
Model the simplest - don’t build a general engine
Collisions: Steps of Analysis
Detect that a collision has occurred
Determine the time of the collision
So can back up to point of collision
Determine where the objects were at time of collision
Determine the collision angle off the collision normal
Determine the velocity vectors after collision
Determine changes in rotation
Circles and Angled Lines
What if more complex background: pinball?
For complex surfaces, pre-compute and fill an array with collision points (and surface normals)
Circle on Wall Collision Response
Determine the time of collision ( tc
tc= ti+ (xh-x1)/(x2-x1
)* Δ t
ti= initial time
Δ t = time increment
Determine where the objects are when they touch
_y c = y 1
(y 1 -y 2 ) * (t c -t i_
)/ Δ t
Determine the collision angle against collision normal
Collision normal is the surface normal of the wall in this case