{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lectureC-physics

# lectureC-physics - Basic Game Physics Based on The Physics...

This preview shows pages 1–8. Sign up to view the full content.

Basic Game Physics Based on The Physics of the Game, Chapter 13 of Teach Yourself Game Programming in 21 Days, pp. 681-715

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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
Game Physics • Approximate real-world physics • We don’t want just the equations • We want efficient ways to compute physical values • Assume fixed discrete simulation – constant time step • Must account for actual time passed for variable simulation • Assumptions: • 2D physics, usually easy to generalize to 3D (add z ) • Rigid bodies (no deformation) • Will just worry about center of mass • Not accurate for all physical effects • Constant time step

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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 v y v x ( x 0 , y 0 ) v : velocity
Acceleration • Acceleration ( a ): change in velocity per unit time Acceleration Velocity Approximate

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Acceleration • Constant acceleration: v x += a x , v y += a y • Variable acceleration: • use table lookup based on other factors: acceleration = acceleration_value(gear, speed, pedal_pressure) • Cheat a bit: acceleration = acceleration_value(gear, speed) * pedal_pressure a x = cos (v) * acceleration a y = sin (v) * acceleration • Piece-wise linear approximation to continuous functions
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 -2 m i : 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)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 32

lectureC-physics - Basic Game Physics Based on The Physics...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online