Introduction to Game Physics 1
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
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
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
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 GameTime)
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 GameTime)
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 *= rateOfDecay Where 0.0 < rateOfDecay < 1.0
Clamping Keeping a value within a specified range Computation Prevent the object(s) from traveling off-screen Prevent the object(s) from moving too fast Computation float value = MathHelper.Clamp ( valueToClamp, minimumValue, maximumValue);
Other Physics Issues User control for jumping height Input tracking Sequence on keys/buttons\controller’s currentState and previousState State driven JumpingState (velocity can continue to decrease) FallingState (velocity can only decrease) Stuck on ground plane Ground Plane (y > upperLimit could trigger player Death) Grounded state doesn’t apply gravity but can transition to falling/jumping
Simple 2D Physics By Example Demonstration
?
References Maxim, Bruce R. Computer Game Physics