Game Development Reference

In-Depth Information

high-speed collisions will be used to resolve resting contact. This is a significant as-

sumption that needs justifying, and I'll return to it later in the chapter and at various

points further into the topic. To avoid changing terminology later, I'll use the terms

collision
and
contact
interchangeably during this chapter.

When two objects collide, their movement after the collision can be calculated

from their movement before the collision: this is collision resolution. We resolve the

collision by making sure the two objects have the correct motion that would result

from the collision. Because collision happens in such a small instant of time (for most

objects we can't see the process of collision happening; it appears to be instant), we

go in and directly manipulate the motion of each object.

7.1.1

T
HE
C
LOSING
V
ELOCITY

The laws governing the motion of colliding bodies depend on their closing velocity.

The
closing velocity
is the total speed at which the two objects are moving together.

Note also that this is a closing velocity, rather than a speed, even though it is a

scalar quantity. Speeds have no direction; they can only have positive (or zero) values.

Velocities can have direction. If we have vectors as velocities, then the direction is the

direction of the vector; but if we have a scalar value, then the direction is given by

the sign of the value. Two objects that are moving apart from each other will have a

closing velocity that is less than zero, for example.

We calculate the closing velocity of two objects by finding the component of their

velocity in the direction from one object to another:

v
c
=
˙

(
p
b
−

+
˙

(
p
a
−

p
a
·

p
a
)

p
b
·

p
b
)

where
v
c
is the closing velocity (a scalar quantity),
p
a

and
p
b

are the positions of

objects
a
and
b
, the dot (

˙

) is the scalar product, and

p
is the unit-length vector in the

same direction as
p
. This can be simplified to give

(
p
a
−
p
b
)

(
p
a
−

v
c
=−

·

p
b
)

[7.1]

Although it is just a convention, it is more common to change the sign of this

quantity. Rather than a closing velocity, we have a separating velocity. The closing

velocity is the velocity of one object relative to another, in the direction between the

two objects.

In this case two objects that are closing in on each other will have a negative rela-

tive velocity, and objects that are separating will have a positive velocity. Mathemati-

cally this is simply a matter of changing the sign of equation 7.1 to give

(
p
a
−

v
s
=

(

p
a
− ˙

˙

p
b
)

·

p
b
)

[7.2]

where
v
s
is the separating velocity, which is the format we'll use in the rest of this topic.

You can stick with closing velocities if you like: it is simply a matter of preference,

although you'll have to flip the sign of various quantities in the engine to compensate.