Game Development Reference
In-Depth Information
F IGURE 7.3
Interpenetration and reality.
Note that, just like the closing velocity, the penetration depth has both size and sign.
A negative depth represents two objects that have no interpenetration. A depth of
zero represents two objects that are merely touching.
To resolve the interpenetration we check the interpenetration depth. If it is already
zero or less, then we need take no action; otherwise, we can move the two objects apart
just far enough so that the penetration depth becomes zero. The penetration depth
should be given in the direction of the contact normal. If we move the objects in the
direction of the contact normal, by a distance equal to the penetration depth, then the
objects will no longer be in contact. The same occurs when we have just one object
involved in the contact (i.e., it is interpenetrating with the scenery of the game): the
penetration depth is in the direction of the contact normal.
So we know the total distance that the objects must be moved (i.e., the depth)
and the direction in which they will be moving; we need to work out how much each
individual object should be moved.
If we have only one object involved in the contact, then this is simple: the object
needs to move the entire distance. If we have two objects, then we have a whole range
of choices. We could simply move each object by the same amount: by half of the in-
terpenetration depth. This would work in some situations but can cause believability
problems. Imagine we are simulating a small box resting on a planet's surface. If the
box is found slightly interpenetrating the surface, should we move the box and the
planet out of the way by the same amount?
We have to take into account how the interpenetration came to be in the first
place, and what would have happened in the same situation in reality. Figure 7.3
shows the box and planet, in penetration, as if real physics were in operation. We'd
like to get as near to the situation in part B of the figure as possible.
To do this we move two objects apart in inverse proportion to their mass. An
object with a large mass gets almost no change, and an object with a tiny mass gets
to move a lot. If one of the objects has infinite mass, then it will not move: the other
object gets moved the entire way.
The total motion of each object is equal to the depth of interpenetration:
p a +
p b =
d