Game Development Reference
ing, how about using particles to simulate debris flung from an erupting volcano as a
special effect in your adventure game set in prehistoric times? Remember the Wooly
Willy toy? To make particles a direct part of game play, consider a diversionary appli‐
cation where you drag piles of virtual magnetic particles around a portrait photograph,
giving someone a lovely beard or mustache much like Wooly Willy.
Hopefully, you're now thinking of creative ways to use particles in your games. So, let's
address implementation. There are two basic ingredients to implementing a particle
simulator: the particle model and the integrator . (Well, you could argue that a third basic
ingredient is the renderer , where you actually draw the particles, but that's more graphics
than physics, and we're focusing on modeling and integrating in this topic.)
The model very simply describes the attributes of the particles in the simulation along
with their rules of behavior. We mean this in the physics sense and not the AI sense in
this topic, although in general the model you implement may very well include suitable
AI rules. Now, the integrator is responsible for updating the state of the particles
throughout the simulation. In this chapter, the particles' states will be described by their
position and velocity at any given time. The integrator will update each particle's state
under the influence of several external stimuli—forces such as gravity, aerodynamic
drag, and collisions.
The rest of this chapter will walk you through the details of a simple particle simulation
in an incremental manner. The first task will be to simulate a set of particles falling under
the influence of gravity alone. Even though this sounds elementary, such an example
encompasses all of the basic ingredients mentioned earlier. Once gravity is under con‐
trol, we'll show you how to implement still air drag and wind forces to influence the
particles' motion. Then, we'll make things more interesting by showing you how to
implement collision response between the particles and a ground plane plus random
obstacles. This collision stuff will draw on material presented in Chapter 5 , so be sure
to read that chapter first if you have not already done so.
Figure 8-1 through Figure 8-4 show a few frames of this example simulation complete
with obstacles and collisions. Use your imagination here to visualize the particles falling
under the influence of gravity until they impact the circular objects, at which time they
bounce around and ultimately settle on the ground.