Presentation on theme: "Real-Time Game Physics"— Presentation transcript:
1 Real-Time Game Physics Approaches to create realistic motion for a game:For artists to author keyframe animations that give the appearance of being physically based.2. Use motion capture technology to record real-life motions and then apply those recorded motions to game models.Both of approaches 1 & 2 are extremely labor intensive, and expensive.3. Simulation of physics represents a third approach to generating realistic motion for games.Benefits:a cost savings to developers and publishers. Physics simulation has the potential to be far less expensive than keyframe or motion capture animation.By simulating physics at runtime, the game engine can create emergent behavior, leading to a richer game experience for the game player.
2 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsThe importance of consistent unitsIt is necessary that you use consistent units in your equations.Equations will produce the wrong results if you use values with inconsistent units!Particle kinematicsParticle kinematics are the basis for everything that follows.A particle to be a perfectly smooth, frictionless sphere with a finite radius.At any moment in time, t, the particle is located at a position, p, measured in an inertial reference frame.Position is measured in units of type distance or length. The SI units for position are meters (m).If the particle is moving, its position is a function of time, p(t).
3 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsParticle kinematicsAt any moment in time, t, the particle is located at a position, p, measured in an inertial reference frame.Position is measured in units of type distance or length. The SI units for position are meters (m).If the particle is moving, its position is a function of time, p(t).The quantity, Δt, indicates an incremental change in time. The SI units for time are seconds.The vector quantity, velocity, is defined to be the change in position over time.The magnitude of velocity is the particle’s speed.Velocity and speed are measured in units of type distance over time. The SI units for velocity and speed are meters per second (m/s).
4 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsParticle kinematicsThe vector quantity, velocity, is defined to be the change in position over time.The magnitude of velocity is the particle’s speed.Velocity and speed are measured in units of type distance over time. The SI units for velocity and speed are meters per second (m/s).Given the position of a particle at two different times, the average velocity between the start and end time can be computed asInstantaneous velocity at time t is the time derivative of position:
5 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsParticle kinematicsAcceleration is measured in units of type distance over the square of time. The SI units foracceleration are meters per second squared (m/s2).
6 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsNewton’s famous lawsNewton’s First Law of Motion states that an object will move at a constant velocity until compelled to change its velocity by forces imposed upon the object.Newton’s Second Law of Motion states that an object’s change in velocity is proportional to an applied force:F(t) = ma(t)The quantity, m, is called the mass of the object. The SI units for mass are kilograms (kg). Force is measured in units of type mass times distance over the square of time. The SI units for force are called Newton’s (N).The cycle of motionForce -> Acceleration -> a change in velocity -> a change in the position of a particle.By integrating the equations in reverse order, we can determine the motion of the particle.This is what physics simulation is all about.The effect of a constant force on particle motion
7 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsNewton’s famous lawsThe effect of a constant force on particle motionConsistency of units, still important
8 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsNewton’s famous lawsThe effect of a constant force on particle motionProjectile motionHere, we’ve chosen the up direction to be the positive z-axis in world space
9 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsNewton’s famous lawsFrictionless collision responseLinear momentum is defined to be the vector quantity mass times velocity, or mV.Linear momentum is measured in units of type mass times distance over time.The SI units of linear momentum are kilogram-meters per second (kg-m/s).Linear momentum is related to the force being applied to an object.Consider two colliding particles, 1 and 2. For the duration of the collision, eachparticle exerts a force on the other.The duration of most collisions is an extremely short period of time, and yet the change in velocity of the objects is often dramatic.Linear impulse-momentum equation:
10 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsNewton’s famous lawsFrictionless collision responseNewton’s Third Law of Motion states that for every action there is an equal but opposite reaction.The (coserved) linear impulse-momentum equation for particle 2:The net change in momentum of the two objects together is zero.Without friction, the impulse will always act purely along the unit surface normal vector at the point of contact.Observe the behavior when two objects in real life collideDuring the initial impact, both objects experience a period of deformation in which their shapes compress and deform in response to the collision force.
11 Real-Time Game Physics Rewind: A Fresh Look at Basic PhysicsNewton’s famous lawsFrictionless collision responseAfter the initial impact, the objects experience a period of restitution, in which they are restored to their natural shapes and accelerate to their after-collision velocities.In real life, as objects rebound after a collision, they may also slide past one another, remaining in contact for a while.The scalar ε is called the coefficient of restitution.This coefficient is related to the conservation orloss of kinetic energy during a collision.If ε is equal to 1, the collision is perfectly elastic,representing objects that rebound fully so thatthe sum of the particles’ kinetic energies is the same before and after the collision.If ε is equal to 0, the collision is perfectly plastic, representing objects that experience no period of restitution and a maximum loss of kinetic energy.In real life, ε is a function of the material properties of the objects involved in the collision.Finally:
13 Real-Time Game Physics Introduction to Numerical Physics SimulationNumerical simulation to a series of techniques that allow us to approximate the motion of objects with non-constant acceleration for which there is no closed form solution, e.g. wind and spring forces.Numerical integration of the Newtonian equation of motionFinite difference equation/Taylor series expansion of a vector property:Truncated Taylor series:For one particle:
14 Real-Time Game Physics Introduction to Numerical Physics SimulationUsing numerical integration to simulate a collection of particlesFor a collection of N particles: S(t) = <m1V1, … mnVn> dS(t)/dt=<<F1,V1>, … <Fn, Vn >>
15 Real-Time Game Physics Introduction to Numerical Physics SimulationCollision response in the simulation loopAssume collision at exact time t, before execute DoPhysicsSimulationStep , for each colliding pair, compute the impulse, and then compute the after-collision linear momentums.Subtle complexity in the collision response:Collision occurs between time t and t+Δt, i.e. between 2 time steps.Multiple object collisions at same or different times within ΔtAlternative collision response methodPenalty force methods with stiff spring between colliding objects
16 Real-Time Game Physics Introduction to Numerical Physics SimulationNumerical stability issues and alternatives in explicit Euler integrationTruncation error is always present in numerical integration.Error at each step accumulates into a total error in the state vector that may grow or shrink over time.A critical goal in numerical simulation is to ensure that the total error is bounded;.A numerical simulation in which the total error is bounded for all time is said to be numerically stable.Numerical integration techniques are said to be conditionally stable if they can be made stable by reducing the time step, Δt, below some threshold, a stability bound.Velocity-less Verler integrator
17 Real-Time Game Physics Introduction to Numerical Physics SimulationThe importance of frame-rate independence
18 Real-Time Game Physics Common Features of Third-Party Physics EnginesStatic and kinematic objectsAn example of a static object is the terrain or level geometry for a typical platformer game.A kinematic object is called kinematic because it moves (and therefore has kinematic properties that change over time) but is not simulated using physics.Rigid body dynamicsRigid body dynamics refers to the simulation of objects that move and rotate based on the equations of motion with real-time physics, but that never deform or change shape.Rigid body dynamics are probably the most common type of physics-based simulation seen in games today.Soft body dynamicsSoft bodies have geometry that does deform based on applied forces and interaction with other objects.A soft body’s center-of-mass moves and rotates according to the equations of motion; however, in addition to this overall motion, the body’s shape deforms.
20 Real-Time Game Physics Common Features of Third-Party Physics EnginesConstraintsConstraints are used to limit the motion of physically simulated objects in games.Hinge joint constraint would generate forces or impulses to prevent the door from rotating except along the axis of the hinge.Joint limits can prevent the door from opening beyond, say, 90 degrees.Ball joints allow two rigid bodies to rotate freely but limit translation.Sliding joints allow translation only along a certain axis, and others.Ragdoll and character physicsRagdolls are basically versions of a character’s skeleton where the keyframe animated bones have been replaced by rigid bodies that have been linked together by joints.Fluid dynamicsAuthoring physics contentEmerging trendsTo support game objects that can be damaged and destroyed.Transition toward using the GPU to perform some of the physics computations.