Game Development Reference
2D Rigid-Body Simulator
After reading Chapter 8 , you've learned the main ingredients that go into a simulator,
specifically a particle simulator. In this chapter we'll look beyond particles at 2D rigid
bodies. The main difference here is that rigid bodies rotate, and you must deal with an
additional equation of motion—namely, the angular equation of motion relating a rigid
body's angular acceleration and inertia to the sum of all moments (torques) acting on
the rigid body. The fundamental elements of the simulator—the model, integrator, ren‐
derer, etc.—are the same as before; you just have to deal with rotation. In two dimen‐
sions, handling rotation is simple. Things get a bit more involved when handling rota‐
tion in three dimensions, and we'll treat that problem in Chapter 11 .
The example we'll take a close look at in this chapter is simple by design. We want to
focus on the differences between the particle simulator and a 2D rigid-body simulator.
In Chapter 10 , we'll extend this simple example to deal with multiple rigid bodies and
collisions. That's where things really get interesting. For now, we'll consider a single rigid
body, a virtual hovercraft, that moves around the screen under the influences of thrust
forces that you can control with the keyboard. While simple, this example covers the
most fundamental aspects of simulating 2D rigid bodies.
Figure 9-1 shows our virtual hovercraft. The pointy end is the front, and the hovercraft
will start off moving from the left side of the screen to the right. Using the arrow keys,
you can increase or decrease its speed and make it turn left or right (port or starboard).