Game Development Reference

In-Depth Information

You can handle aggregating the forces in a few ways. You could aggregate all the forces

on all objects prior to looping through the objects integrating the equations of motion,

but this would require looping through all the objects twice. Alternatively, since you're

looping through the object list in order to integrate each object's equations of motion,

you can simply aggregate each object's forces during the integration step. A complication

arises when object pairs apply forces to each other. A linear spring and damper, for

example, connected between two objects, apply equal and opposite forces to each object.

The force is a function of the relative distance between the objects (the spring compo‐

nent) and their relative velocity (the damping component). So, if during a given time

step you aggregate the forces on one of the objects in the pair, the resulting force will

be a function of the current relative position and velocities of the objects. Integrating

that object will give it a new position and velocity. Then, when you get to the other object

in the pair, if you recomputed the spring force, it will be a function of the new relative

position and velocity between the objects that includes the new displacement and ve‐

locity of the previously updated object but the old displacement and velocity of the

current object. This is inconsistent with Newton's law of equal and opposite forces. You

can resolve this problem by storing the force computed for the first object and applying

it to the second one without recomputing the spring force for the second object.