Game Development Reference

In-Depth Information

While we're on the subject of tuning, we should mention that you'll also have to play

with the linear drag coefficient used to calculate the drag force on the hovercraft. While

this coefficient is used to simulate fluid dynamic drag, it also plays an important role in

terms of numerical stability. You need some damping in your simulation so that your

integrator does not blow up—that is, damping helps keep your simulation stable.

That's pretty much it as far as implementing basic collision response. If you run this

example, you'll be able to drive the hovercraft into each other and bounce off accord‐

ingly. You can play around with the mass of each hovercraft and the coefficient of res‐

titution to see how the craft behave when one is more massive than the other, or when

the collision is somewhere between perfectly elastic and perfectly inelastic.

You may notice that the collision response in this example sometimes looks a little

strange. Keep in mind that's because this collision response algorithm, so far, assumes

that the hovercraft are round when in fact they are rectangular. This approach will work

just fine for round objects like billiard balls, but to get the level of realism required for

non-round rigid bodies you need to include angular effects. We'll show you how to do

that in the next section.

Angular Effects

Including angular effects will yield more realistic collision responses for these rigid

bodies, the hovercraft. To get this to work, you'll have to make several changes to

ApplyImpulse
and
CheckForCollision;
.
UpdateSimulation
will remain unchanged.

The more extensive changes are in
CheckForCollision
, so we'll discuss it first.

The new version of
CheckForCollision
will do more than a simple bounding circle

check. Here, each hovercraft will be represented by a polygon with four edges and four

vertices, and the types of contact that will be checked for are vertex-vertex and vertex-

edge contact (see
Figure 10-2
).
1

1. Note that this function does not handle multiple contact points.