Game Development Reference
In-Depth Information
CHAPTER 10
Implementing Collision Response
In this chapter, we'll show you how to add a little excitement to the hovercraft example
discussed in the preceding chapter. Specifically, we'll add another hovercraft and show
you how to add collision response so that the hovercraft can crash into each other and
bounce off like a couple of bumper cars. This is an important element for many types
of games, so it's crucial that you understand the code that we'll present here. Now would
be a good time to go back and review Chapter 5 to refresh your memory on the funda‐
mentals of rigid-body collision response since we'll use the principles and formulas
discussed there to develop the collision response algorithms for the hovercraft simula‐
tion. In Chapter 8 you saw how to implement linear collision response for particles, and
now we'll show you how to handle angular effects.
To start simply, we'll first show you how to implement collision response as if the hov‐
ercraft were a couple of particles just like those in Chapter 8 . This approach uses only
linear impulse and does not include angular effects, so the results will be somewhat
unrealistic for these hovercraft; however, this approach is applicable to other types of
problems that you may be interested in (for example, billiard ball collisions). Plus, taking
this approach allows us to show you very clearly the distinction between linear and
angular effects. Including angular effects will make the simulation much more realistic;
when the hovercraft crash into each other, not only will they bounce off each other, but
they will also spin.
Before diving into collisions, let's add another hovercraft to the example we started in
Chapter 9 . Recall in that example, we had a single craft that you could control using the
keyboard. Now, we'll add another hovercraft that simply moves under constant forward
thrust. Later, when we add collision detection and response you'll be able to run into
this new hovercraft to alter its course.
Referring back to the example from Chapter 9 , we need to add another craft as follows:
RigidBody2D Craft2;
 
Search Nedrilad ::




Custom Search