Game Development Reference
R ESTING C ONTACTS
Consider the situation shown in figure 7.4. We have a particle resting on the ground.
It is experiencing only one force, gravity. In the first frame the particle accelerates
downward. Its velocity increases, but its position stays constant (it has no velocity at
the start of the frame). In the second frame the position is updated, and the velocity
increases again. Now it is moving downward and has begun to interpenetrate with
the ground. The collision detector picks up on the interpenetration and generates a
The contact resolver looks at the particle and sees that it has a penetrating velocity
Applying the collision response, the particle is given a velocity of
and is moved out of interpenetration. In frame 3, therefore, it has an upward velocity,
which will carry it off the ground and into the air. The upward velocity will be small,
but it may be enough to be noticed. In particular, if frame 1 or 2 is abnormally long,
the velocity will have a chance to significantly build up and send the particle skyward.
If you implement this algorithm for a game with a variable frame-rate and then slow
down the frame-rate (by dragging a window around, for example, or having email
arrive in the background), any resting objects will suddenly jump.
To solve this problem we can do two things. First we need to detect the contact
earlier. In the example two frames have passed before we find out that there is a prob-
lem. If we set our collision detector so it returns contacts that are nearly, but not quite
interpenetrating, then we get a contact to work with after frame 1.
Second we need to recognize when an object has velocity that could only have
arisen from its forces acting for one frame. After frame 1, the velocity of the particle is
caused solely by the force of gravity acting on it for one frame. We can work out what
the velocity would be if only the force acted on it, by simply multiplying the force by
the frame duration. If the actual velocity of the object is less than or equal to this value
(or even slightly above it, if we acknowledge that rounding errors can creep in), we
F IGURE 7.4
Vibration on resting contact.