Introduction to Game Physics 1 Game Physics Not

  • Slides: 12
Download presentation
Introduction to Game Physics 1

Introduction to Game Physics 1

Game Physics • Not trying to build a perfect physical model • Most things

Game Physics • Not trying to build a perfect physical model • Most things can be approximated assuming Newtonian physics and rigid bodies • Use discrete simulation (constant step) techniques 2

Why Physics The Human Experience • Real-world motions are physically-based • Physics can make

Why Physics The Human Experience • Real-world motions are physically-based • Physics can make simulated game worlds appear more natural • Makes sense to strive for physically-realistic motion for some types of games Emergent Behavior • Physics simulation can enable a richer gaming experience 3

Physics of Motion Terms Position • The vector indicating the location of a point

Physics of Motion Terms Position • The vector indicating the location of a point relative to the coordinate system’s origin Velocity • The rate of change of the position of an object Acceleration • The rate at which the velocity of an object changes with time 4

Position and Velocity • Where is the object at time t (using pixels)? Computation

Position and Velocity • Where is the object at time t (using pixels)? Computation position(t) += velocity * dt Where dt is the amount of time passed since the last Update (either calculated programmatically or via Game. Time) 5

Acceleration • Where is the objects rate of change (using pixels)? Computation velocity +=

Acceleration • Where is the objects rate of change (using pixels)? Computation velocity += acceleration * dt Where dt is the amount of time passed since the last Update (either calculated programmatically or via Game. Time) 6

Friction and Damping • With no acceleration, velocity will only change based upon user

Friction and Damping • With no acceleration, velocity will only change based upon user input • To slow objects down without acceleration * after updating position Computation velocity *= rate. Of. Decay Where 0. 0 < rate. Of. Decay < 1. 0 7

Clamping • Keeping a value within a specified range • Prevent the object(s) from

Clamping • Keeping a value within a specified range • Prevent the object(s) from traveling off-screen • Prevent the object(s) from moving too fast Computation float value = Math. Helper. Clamp ( value. To. Clamp, minimum. Value, maximum. Value); 8

Other Physics Issues • User control for jumping height • Input tracking • Sequence

Other Physics Issues • User control for jumping height • Input tracking • Sequence on keys/buttonscontroller’s current. State and previous. State • State driven • Jumping. State (velocity can continue to decrease) • Falling. State (velocity can only decrease) • Stuck on ground plane • Ground Plane (y > upper. Limit could trigger player Death) • Grounded state doesn’t apply gravity but can transition to falling/jumping 9

Simple 2 D Physics By Example • Demonstration 10

Simple 2 D Physics By Example • Demonstration 10

References • Maxim, Bruce R. Computer Game Physics 12

References • Maxim, Bruce R. Computer Game Physics 12