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.
The future is for levels to be built not like 3D worlds, with 'a castle' and 'a watch tower' dumped onto a map as a single entity, but for them to be constructed out of pieces like their real world counterparts with each component capable of being affected by the player directly.
In this kind of map, you could deal with a sentry in a tower by either shooting him with a sniper rifle as usual, or grabbing a car and ramming one of the legs to make it topple over. Instead of being a scripted sequence or a set-piece added by the designers, you could solve every situation by thinking out of the box confident that every action really would get the right reaction. Crysis recently took the biggest steps in this direction, but there's still a long way to go.
Soft bodies bend best
The next level up is soft-body physics. These are what you use for more bending objects, squish, be sliced up, or otherwise be flexible. To get a better idea of the difference between these and rigid body calculations, imagine the difference between throwing a rope at a wall, and throwing a cardboard box.
Cloth is one of the most common soft-body effects, and an excellent demonstration of an item that can be torn, twisted, ripped, and take the form of other objects. Due to the incredible amount of maths required, most games still cheat with keyframe-based animation or rigid body physics on things like ponytails.
In future games, characters will be able to wear clothes just like we do, baggy in all the right places, and every bit as subject to the effects of wind, rain. The possibility of doing the same with bladed weapons could make for at least one fantastic Tomb Raider sequel.
The main reason cloth is so difficult to render is that it's incredibly mathematics heavy, especially when it comes to controlling deformations and preventing its own polygons from intersecting. As a result, it's rarely been anything but a gimmick, thrown in every now and again in games like Splinter Cell.
Into the vortex
One of the most vivid demos came with the launch of PhysX, and the CellFactor demo. For a while, this was roundly mocked online after gamers realised that by simply adding 'Enable PhysX=false' to the configuration file, anyone could smash their way through crates and experiment with the impressive vortex effects and insane numbers of polygons on screen at once.
However, as soon as cloth was added to the mix, performance on machines with no hardware support instantly dropped to a single-digit fps, vindicating the hardware… at least, in part.
The final key type of physics engine on offer is the particle engine, used to create everything from explosions and flowing water to flamethrowers, and effects on every level. The designer starts with an emitter, which sprays out particles – think of them as dots, with no mass or other effect. These can be treated like fluid, if channelled and made subject to the laws of gravity, or sprayed up into the air to be caught by virtual wind.
On their own, they're invisible and not even there, but when the designer attaches the right texture or shader, the effects can be mindblowing. In practice, most games cheat considerably here, with particle effects used exclusively for visual feedback, and the actual calculations taking place under the hood.
It's not the fire itself that burns you, but the designer assigning the bit of the ground underneath it to do so. Either that or the game doing some quick mathematics to see if you're standing in range of the flamethrower's arc of fire.
Feelings of Euphoria
The most exciting development for in-game physics in the last couple of years hasn't been cards, but rather Euphoria – a behaviour based engine aimed at in-game characters. It's not geared towards physics in itself, certainly not in the same way as Havok and PhysX, but it definitely contributes to the overall effect within a proper world simulation.
One of the first uses of dedicated physics coding in games was for 'ragdoll' effects – in short, making enemies react properly after death. By giving each character model a full skeleton, connected and animated using inverse kinematics, the limp corpse could half- hang over railings, slip down stairs, or even be picked up and rearranged into hilarious screenshots to amuse the whole internet. Well, in theory…
This was one of the most visible demonstrations of in-game physics until Half-Life 2 came along, and notable because it only kicked in after death – actual actions were still a matter for key-framed animation, unstoppable, unchangeable, and often clunky.
Euphoria changes this by focusing not on individual animations but 'behaviours', with characters given instructions of how to act, and the freedom to do so within the physical simulation. Where a regular character might be stuck watching the player escape on a moving platform, a Euphoria powered one might leap across, grab the edge with one hand, and clamber up to continue the fight.
Instead of each hit part of the body counting, a player could shoot a character in the leg and watch it react with a pain animation before falling flat on its backside with a scream. As with ragdolls and other physics engines, none of this happens magically – the developers still have to make it all work, and tell the characters how to react. But it opens the door for far more realistic situations, and most importantly, more unique gaming experiences than any canned animation could attempt to provide.
Grand Theft Auto 4 was the first game to ship with Euphoria support with one of the most amusing examples. Victims of carjacking are now likely to wind up taking a long trip after trying to take back their property when you've already got your foot on the pedal. with one hand on the handle, they will bounce up and down on the road until shaken loose.
Other games due to ship with Euphoria support include Lucasarts' Sith-simulator The Force Unleashed, the next Indiana Jones game, and an American football title, Backbreaker.
The Future of Physics
Right now, adding an impressive physics engine is seen as a selling point in itself, but as with the advances in 3D graphics, this won't last for long. However, when you've played in a world that makes you feel like you're there, nothing else will ever feel quite right again.
Just step back a few years to games without skeletal animation systems, or the completely canned deaths that were vogue before ragdolls, and you'll see just how important even the smallest details are. The goal for makers of physics engines isn't anything as specific as photorealism or the creation of a sentient computer, but for a game's world that is consistent, accessible and without barriers to the player.
The irony is that when developers finally succeed, the results are going to be so good, you'll be too busy enjoying it to notice.