Chapter 8. Particles

In this chapter we’ll show you how to apply what you’ve learned in Chapter 7 in a simple particle simulator. Before getting to the specifics of the example we’ll present, let’s consider particles in general. Particles are simple idealizations that can be used to simulate all sorts of phenomena or special effects within a game. For example, particle simulations are often used to simulate smoke, fire, and explosions. They can also be used to simulate water, dust clouds, and swarms of insects, among many other things. Really, your imagination is the only limit. Particles lend themselves to simulating both discrete objects like bouncing balls and continua like water. Plus, you can easily ascribe an array of attributes to particles depending on what you’re modeling.

For example, say, you’re modeling fire using particles. Each particle will rise in the air, and as it cools its color will change until it fades away. You can tie the particle’s color to its temperature, which is modeled using thermodynamics. The attribute you’d want to track is the particle’s temperature. In a previous work, AI for Game Programmers (O’Reilly), this book’s coauthor David M. Bourg used particles to represent swarms of insects that would swarm, flock, chase, and evade depending on the artificial intelligence (AI). The AI controlled their behavior, which was then implemented as a system of particles using principles very similar to what you’ll see in this chapter.

Particles are not limited ...

Get Physics for Game Developers, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.