Computer games get physical

 

You can’t have a realistic gaming experience without using the rules of physics – the calculations involved are what make the difference between stick figures that jitter across the screen and 3D characters that sweat and stumble, writes Cian Traynor

TODAY’S MOST advanced computer games are powered by software called physics engines. Loaded with a library of scientific definitions, they allow computer games to predict how an object should behave by translating what happens in the real world.

When computer games were animated manually, almost everything was pre-scripted. If your player knocked over an object, it fell the same way every time. Now predefined animations have been replaced with fluid movements, allowing for different possibilities and greater realism. If you knock into a crate from the side, it will fall properly to the left or right depending on how you knocked into it, making the scene so interactive that the characters’ actions and reactions can be different every time.

“What we’re really doing is the kind of equations people learn in fifth and sixth year physics classes,” says Dave Gargan, vice president of engineering at Havok, a Dublin-based software company whose engines are used in over 200 titles including Halo 3and Half-Life 2.

When Half-Life 2was released in 2004, its pioneering use of physics helped usher in a new era of interactive gaming. The player often had to manipulate objects while accounting for factors such as gravity, mass, density and restitution – all of which needed to be computed as they happened.

“Newton’s laws of motion are exactly what we’re calculating in each frame,” says Gargan. “Every time the computer draws a new image, we have to compute all those equations about 30 times a second and solve them.The only problem is doing that computation quickly enough.”

Integration calculates the future position of an object, such as a character or a car, based on its current position, velocity and acceleration. To free up enough computation time, elements of the game that aren’t in use remain in “sleep mode”.

In a racing game, for example, a barrier only becomes “awake” when a car crashes into it. This is where collision detection comes into play: it works out when one thing hits another thing and how it hits it. Without those calculations, characters would walk through walls.

“When you see games that don’t utilise physics, your eyes can tell,” says Chris Allen, lead behaviour engineer at NaturalMotion, whose Euphoria engine is used in Grand Theft Auto IV, Red Dead Redemptionand Star Wars: The Force Unleashed.

“The biggest law of physics in games is the conservation of momentum, because if a guy stops instantly, it makes things look artificial.”

If you get the building blocks of physics right – from how a shoulder joint should move to how a bullet should bounce – it doesn’t matter how complex or how big that virtual world becomes.

“If you can calculate how a bullet collides with a brick then you can make a wall, then a house and then a city,” says Allen. “The rules of collision will work in all situations, so you can build away without having to worry whether something like ballistics will still work.”

By handling all the game physics, these engines give developers more time to work on other aspects of the game, such as graphics and storylines.

This means that not only can the engine and content be designed separately but reusable engines make it easier and faster to develop sequels to games.

the Hollywood effect

When real life just isn’t that interesting, physics engines also allow computer-game developers to bend the rules of physics to make a game more entertaining.

“For a lot of things, our perception of what’s real is actually dictated by things we see in movies,” says Gargan. “By default we set gravity to be a constant as it is on earth: 9.8 metres per second. But some developers might want to double the speed of gravity because, in certain scenes, things falling much faster and colliding much harder just looks more dramatic.”

Bringing characters to life in Grand Theft Auto IV, the Euphoria engine uses the computer’s CPU to generate motion as it happens – right down to simulating the character’s muscle and nervous systems. Each movement of the body is modelled from real-life examples recorded by motion capture data at a studio.

“The characters are not puppets on a string,” says Allen. “Different parts of the body have different limits they have to obey. Once you’ve got them correctly modelled, it’s not difficult to make your character act like a real person who can react to the world around them.

“Rather than having 10 different ways they can respond to things, they can respond in an infinite number of ways and it’s unique every time.”

When characters were killed off in early computer games, death sequences were the same for any situation. As technology developed, it became possible for characters to fall to the ground when they were killed or even to clutch the place where they were wounded.

These sequences, known as “ragdoll physics”, were advanced even further by the Euphoria engine which allows characters to take a hit, stumble, and then recover themselves.

These “ragdoll” sequences consist of a series of connected rigid bodies programmed to have Newtonian physics acting upon them, generating effects that traditional animation can’t compete with – such as when the upper-body weight of a character who’s slumped over a cliff forces him to fall over the edge.

shootouts and ricochets

The simplest way of tracing the path of a bullet is called “hitscan”. When a gun is fired, the game assumes that the projectile travels like a laser beam bouncing off a mirror – in a straight line at infinite speed.

It’s then calculated whether that beam intersects with another object, such as a character, before registering it as a hit.

“You need to know how it hit the surface, what angle it hit the surface at and what sort of properties the surface has,” says Gargan. “Then we use some basic 3D linear algebra – basically vectors on the maths syllabus in secondary school – which help us work out where it would go. It’s a very simple set of equations.”

Some games such as Battlefield: Bad Company 2enhance this process to approximate real-life ballistics by adding in factors like gravity and bullet weight (which causes the bullet to fall in flight) and realistic range. This means that firing at a moving target that’s far away requires you to aim your sites above and ahead of the target’s path to compensate for drop and travel time.

particle systems: blood, sweat and tears

Effects such as smoke, sparks, blood, fire and water are all made up a system of particles that behave according to a set of rules. Once the properties of the particles, like velocity, weight and acceleration, are defined, basic laws of physics such as gravity and momentum transfer can be tweaked to give the desired effect. The more laws of physics integrated, the better the gameplay.

In a game like EA Sports’ MMA(mixed martial arts), close contact between fighters means the gradual build-up of injuries is crucial to making the sport appear life-like. Whereas picking up an object might not change a character’s composition, looking the same after repeated blows to the face just wouldn’t be convincing.

To create the effect of an impact on a fighter’s face, the makers of the game developed a damage model to realistically capture how cuts turn into bleeding and swelling.

Once the direction and force of a punch is fed into the simulation, particle systems are used to trigger the spray of blood, sweat and spit through the air in a “stringy” effect, while small bursts of the particle flow are sampled to transfer blood to the opponent’s body and the ground beneath their feet.

burning rubber

F1 2010is powered by an engine created especially for the title so that the race cars can mimic the physics of their real-life counterparts.

It computes figures obtained from the official Formula 1 teams, such as the cars’ rate of acceleration and deceleration, g-force and aerodynamics, tyre models, as well as average lap times and braking distances.

“As a gamer, I never liked playing a racing game that didn’t conform to reality,” says Codemasters’ Stephen Hood, who developed the title.

“Ultimately you want the physics engine to be as complicated as possible and then you can apply things on top of that to make it easier for players to control.” Like EA Sports’ MMA, the game’s engine allows the car to build up gradual damage: parts of the bodywork can be clipped or dented and it never goes back to a pre-determined state like older racing games.

The individual mass of car parts even influences the front and rear weight balance of the car, while the effects of friction and temperature wear out the tyres and falling rain loosens the track’s grip.

For Hood, these seemingly small details have a knock-on effect on the performance of the game, immersing the player.

“When you’re following another car, you’re in its channel of clean air. The physics engine then detects the need to reduce air density and processes that equation, which allows the car to pick up speed, which in turn heats the engine up – just like in real life. We’ve thought of everything!”

explosions and debris

One advantage of physics engines is that no two explosions are ever the same – just like in real life. A realistic rocket blast should leave a trail of smoke behind it and when it hits an object, the pieces that fly away need to obey the laws of physics too.

The outcome of an explosion depends on what other objects are around it to block the blast and where the initial detonation takes place.

When the player throws a grenade or plants a landmine, they’re determining the outcome themselves as the effects of the explosion are computed there and then.

When a Havok engine was used in the climax of Harry Potter and the Order of the Phoenixduring the face-off between Harry and Lord Voldemort, it calculated a realistic trajectory for the broken glass so that the special effects could be added in later.

rigid body dynamics: hair and clothes

In DJ Hero, a game that simulates the art of mixing sounds together, Havok’s cloth tool imitates the movement of soft tissue like fabric and hair on each animated figure in real time. “Whenever you see the DJs with things like hoodies, ponytails or long chains – all of those are simulated on the spot rather than having someone animate them,” says Gargan. “For a ponytail, we might just simulate that as a single pendulum that swings from somebody’s head, then draw in a realistic ponytail over it. We’re always looking for ways to cheat by simulating something far simpler and then applying it to something that looks more complex.”