All you need to know about physics in games

Physics have been part of gaming since the start: Spacewar's little ships not only contended with their opponents' bullets, but the gravity well of the star in the middle of the screen.

To careless players, the wrong move meant instant death. To more experienced pilots, the slingshot effect it created was a key tactic in not only winning the battle, but in humiliating the enemy.

Dedicated physics cards exist, and we'll talk about those later on, but they're not much help at the moment. Whereas developers could support 3D graphics cards and software rendering at the same time on early games, showing off what the new cards could do without restricting their sales to the early-adopter crowd, advanced physics can't simply be treated as an aesthetic option.

Either the game is built for them, or it's not. As a result, most of the games that have supported them have been restricted to unimpressive things like giving explosions a heavy shrapnel boob-job, or adding more clutter to the ground for players to kick around on their way to the next bit of actual game.

Engines of industry

'Physics engine' is a catch-all phrase for the parts of the code that handle every disparate part of a physical simulation. While they have to work together for the effect to be convincing, the easiest way to see the pieces in action is to head back and look at the simpler games that only had to juggle a handful at a time.

Let's use Super Mario Bros' jumping as an example. As well as gravity, it's a great demonstration of simple friction. The speed Mario is running or jumping determines not only his forward momentum after a jump, but determines how much he slides against the ground after landing.

These small tweaks to the platform game formula were pivotal in creating the game's smooth, intuitive feel, to the point that nothing that came afterwards could afford not to do the same kind of thing. Over time, the Mario franchise included different surfaces including ice levels and other friction free surfaces, and the alternative with slower under water movement.

Plug and play

Most modern developers don't code physics from scratch, but plug in a dedicated engine for it. The most common are PhysX and Intel's Havok. It's not a case of simply plugging them in and instantly having a full world to play with, but they handle the tough stuff and leave developers with much more time to worry about how the physics of each world should be handled, rather than how to get it working.

Most of the physics you see in modern games is based on basic rigid body calculations. A simple example would be a crate. You can pick it up, you can put it down, you can stack it, you can smash it, you can stand on it. A box is the simplest kind of object to play with because it's by far the easiest to calculate collisions for.

Wrapping an object in an invisible sphere will work for slightly more complicated objects that don't require much finesse. Of course, ideally you'd perform checks on every single surface directly, but that's not usually necessary, and would soak up a phenomenal amount of processing time. Using simpler objects eases the load, without drastically affecting the results.

Mind those boxes!

Most of the time these physics are deployed is simply for clutter. They give you stuff to knock out of the way while running through levels, and to make the important stuff fall and fly round the map as it should. Exact collisions aren't as important.