Docsity

Basic Game Physics - Computer Game Design - Lecture Slides | EECS 494, Study notes of Electrical and Electronics Engineering

Partial preview of the text

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) = x 0 + v x t
  • y(t) = y 0 + v y t
  • Incremental computation per frame, assuming

constant time step and no acceleration:

  • v x and v y constants, pre-compute
  • x += v x , y += v y vy 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 (m 1 m 2

)/ 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 F friction

= m g μ

  • m = mass, g = 9.8 m/s 2 ,
  • μ = 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 ( t c
  • t c = t i + (x h -x 1 )/(x 2 -x 1

)* Δ t

  • t i = 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
    • Compute angle of line using (x 1 -x h ) and (y 1 -y c

x 1 ,y 1 x 2 ,y 2 xh collision normal