Game Development Reference
In-Depth Information
For example, a jump might be caused first by applying an impulse force to begin
the jump. But once the jump starts, it's the force of gravity that'll bring the char-
acter back down to the ground. Because multiple forces can be acting on an object
at the same time, the most common approach in a game is to sum up all the force
vectors affecting an object and divide this by the mass to determine the current ac-
celeration:
acceleration = sumOfForces / mass
Euler and Semi-Implicit Euler Integration
The simplest type of numeric integration is
Euler integration
, which is named
after the famed Swiss mathematician. In Euler integration, first the new position
is calculated by taking the old position and adding to it the old velocity multiplied
by the time step. Then the velocity is similarly calculated using the acceleration. A
simple physics object that uses this in its update function is shown in
Listing 7.7
Listing 7.7
Euler Integration in Physics Object
class
PhysicsObject
// List of all the force vectors active on this
object
List
forces
Vector3
acceleration
,
velocity
,
position
float
mass
function
Update(
float
deltaTime
)
Vector3
sumOfForces
= sum of forces in
forces
acceleration
=
sumOfForces
/
mass
// Euler Integration
position
+=
velocity
*
deltaTime
velocity
+=
acceleration
*
deltaTime
end
end