An examination of physics in video games
bright spark; Video game physics are something that we often take for granted. If you make your avatar jump, you expect it to come down and not go shooting off into space. Although, if you have played Skyrim long enough, you know that this can happen anyway. However, aside from glitches, quirks, or intentional game physics that don’t mimic the real world, we expect in-game objects to behave in ways that make sense, so we don’t think about that fact that these laws must be baked into the game.
Programming physics into a game can be as simple as one or two routines with a few lines of code each, or as complex as requiring a completely separate physics engine like Havok or PhysX with millions of lines of code. Regardless of the complexity or whether a game engine requires middleware to handle the computations, game physics falls into two broad categories — rigid body and soft body.
Rigid body physics is generally defined as forces that act on a solid object. It is required for most 2D and 3D games. Soft body physics is applying physical forces to a deformable mass — like a flag. Soft body is much more complex to simulate. For this reason, it is used far less and depending on the game, may not be required at all.
In this article, we’ll delve a bit deeper into these two types of physics and explore how and why they are used in video games. We will avoid the deep technical dive for now, but may investigate the complexities further in a future installment.
The Importance of Game Physics
Developers apply physics in games for a variety of reasons, but the most important factors to consider are intuitiveness and fun factor. If an object in a game does not behave in a predictable way, it would be tough for the player to figure out how to play.
For example, if you started a FIFA 20 match and whenever the ball hit the turf it bounced in a random direction, it would be very hard, if not impossible to figure out how to get it down the field and into the goal. Therefore, game makers try to simulate how the ball will bounce based on trajectory, velocity, and other real-world factors, so that the player intuitively knows how to manipulate the ball or any other object. Ironically, FIFA 20 has suffered a spate of bad user reviews precisely because its physics don’t work as fans expected.
However, that is not to say games have to abide strictly to the natural laws of physics. In fact, most developers bend the rules for the sake of fun. The game has to be enjoyable to play after all. If the physical forces are too lifelike, it can ruin the fun factor. For example, imagine what it would be like to play Grand Theft Auto V with unforgiving physics — there’s a mod for that by the way.
Even a slight collision with another object at high speed would result in a wreck ruining the player’s getaway. Not so fun.
So there is a fine line between making a game enjoyable to play and it being physically realistic. It is the responsibility of the developers to strike the proper balance, which is often dependent on the demographic they are targeting. Racers are a good example.
Many gamers enjoy arcade-style racers, like Need For Speed, that don’t punish them too harshly for scraping a guardrail or taking a corner too fast. A smaller demographic prefer sim-racing games that are a closer approximation to reality, such as Gran Turismo. Even when creating sims to satisfy a smaller market, game makers have to find a way to lure other players, or else the game will do too poorly. Gran Turismo initially relied on photorealism to attract other players, which worked to an extent. Still, Polyphony Digital eventually added an arcade mode to the series to cater to a broader market.
Now that we know why game designers employ physics, let’s take a closer look at the two types, how they are used, and what developers do to keep the calculations required from exceeding processing capabilities.
Rigid Body Physics
When we think of video game physics, we are usually considering rigid body physics (RBP) as this is arguably the most important, and something that most games must implement in one way or another. Rigid body physics deals with simulating and animating physical laws on solid masses. For example, the ball in the FIFA 20 case above is a rigid body that is acted on by the game physics.
Whether it is a 2D game like Pong or a 3D such as Skyrim, most video games deal with linear rigid body physics.
2D Video Game Physics
Let’s go all the way back to Pong — two rigid bodies (ball and paddle) repeatedly colliding with each other. Gee, when you put it that way, it doesn’t sound fun at all. The granddaddy of video games did not realistically model real-world physics. For one, its programmers ignored calculations involving gravity, friction, and inertia. It was just a ball going back and forth at a constant speed.
Second, the angle of the ball rebounding from the paddles was not calculated accurately. The ball’s bounce completely ignored the law of reflection. This law states that disregarding other factors such as spin, a ball striking a surface at a given angle will rebound at an equal angle.
In Pong, the reflection angle was determined by the proximity of the impact to the center of the paddle. Regardless of its initial trajectory, the ball’s reflection was based on how far from center it struck the paddle. So players could completely reverse the ball’s momentum, regardless of its incoming vector.
Angular trajectory would come into play more with later iterations and other paddle games like Breakout. However, even then, the numbers were usually fudged. It all comes back to the fun factor. Mimicking deflection too closely to reality was less fun and often more difficult to play.
Artillery games were the first to start incorporating factors like gravity and resistance into the mechanics. For those too young to remember, artillery games were where players would take turns firing cannonballs, arrows, or other projectiles at each other trying to destroy their opponent’s base. These games used semi-realistic ballistics that took account for things like the angle of launch, gravity, wind resistance, and initial velocity. Again, designers did not make the games too true-to-life. Their target audience was the average joe, not ballistics experts.
3D Video Game Physics
The physics used in 3D games is not that much different than what developers used in their 2D cousins. As mentioned before, even the double jump exists in some 3D games. The main difference is the complexity of the computations when adding in a third dimension (z-axis) and objects made up of multiple rigid bodies.
In most 2D games, developers only have to contend with detecting the collision of a few solid objects at a time. For example, Mario landing on top of a Koopa. Any part of Mario can touch any part of the Koopa. How that contact occurs determines whether the Koopa gets bopped or Mario loses a life. Either way, it is only one collision.
Most 3D titles have multiple solid objects interacting with each other. Take the Uncharted series as an example. When Drake scales a cliffside, the program is looking for collisions with at least his hands and feet, which are all separate rigid bodies. If he leaps and only one hand catches a ledge, the animation will be different than if both connect.
Speaking of each limb being a separate rigid body, 3D games (and some 2D) have models with multiple rigid bodies held together at joints. In other words, a human model’s arm may have a hand and a forearm connected at the wrist with that linked to an upper arm and so on. This structure and how it behaves is referred to as “ragdoll physics.”
Ragdoll physics is used in most, if not all, games with player or NPC models. The connections of the various rigid bodies that make up the limbs are created on the game engine’s skeletal animation system. Each rigid body must act under a set of rules to look realistic when moving.
To compute these movements, programmers use a variety of techniques. The most common is Featherstone’s algorithm, which is a constrained-rigid-body approach that keeps the limbs from flying around like airplane props, although sometimes they still do to comedic effect.
Other types of ragdoll handling approaches include Verlet integration (Hitman: Codename 47), inverse kinematics (Halo: Combat Evolved and Half-Life), blended ragdoll (Uncharted: Drakes Fortune and many others), and procedural animation (Medal of Honor series).
All of these techniques attempt to solve the problem of a body going limp too fast and crumpling to the ground with its joints going this way and that like — well, a ragdoll. The rigid bodies making up a model are constrained in their movement so that they behave in a predictable manner, even if the the game’s physics are not completely based in reality.
Just as in 2D titles, game makers have to find a balance between realism and fun. So when computing physical forces within the game, the calculations are often not entirely accurate; that is to say, “the game cheats.”
Take the Sniper Elite series as an example. In the real world, military snipers have to make every shot count, so they consider quite a few factors when lining up a target. Wind speed, wind direction, range, target movement, mirage, light source, temperature, barometric pressure, and the Coriolis effect are just a handful of variables that real-life crack shots have to factor into their position and aiming.
If Rebellion chose to go the route of making an authentic sniping simulation, not only would the game be very difficult for most players, the number of calculations, and thus the amount of programming and processing power would increase significantly. Crunching these variables is not taxing on today’s processors, but the average player does not want calculate these factors when playing, let alone even understand them. Therefore, it is much simpler (and profitable) to just allow the player to line up the target in the crosshairs and let them score a hit, preferably with a slo-mo bullet cam.
That is not to say that games have not attempted to make sniping more complicated. Call of Duty: Modern Warfare has a campaign level that involves taking out a target from long range. The player must contend with the Coriolis effect and wind speed/direction (above). The mission is frustratingly tricky, enough so that I eventually put it down and played something else. That is not to say that some players do not like that challenge. Some called it the best mission in the game. I just don’t have the patience for it.
However, the extra contact points up the calculations done by the physics engine considerably. Fortunately, ACC’s engineers have figured out a way to do this without increasing the computational load so much as to affect game performance negatively.
As you can probably tell, physics models in 3D games can be far more complicated than their 2D counterparts. Many more variables and collisions must be tracked to keep the physics on an even keel. However, most calculations are still linear and, therefore, more straightforward than soft body physics models.
Soft Body Physics
Soft body physics (SBP) deals with deformable objects and is far more complex than RBP, which is why we saved it for last. It’s also less utilized and more simplified in video games than its rigid body counterpart because of the massive amount of computation it requires to simulate realistically. Therefore, all soft-body models in video games are brought down to a manageable level in one way or the other due to processing limitations.
Some soft body physics examples would be cloth, hair, and collections of particles like smoke or mist. Unlike a rigid body where any two points remain the same distance from one another, soft bodies can morph and move so that two points on the body can move closer or further from each other.
Soft Body Solids
There can be many restrictions on the amount of movement in a soft body, or there can be none. For instance, let’s look at a flag. All points on the flag are constrained to remaining on that flag — they can’t just go flying off into space. However, as the flag moves, the distance between any two points can vary. The range that they can move away or toward each other depends on the distance between them when the flag is flat.
In other words, adjacent points are constrained to remain adjacent, while distant ones can move close enough to become adjacent but cannot become more distant than their flat state span. The number of configurations of all the points on the flag, while finite, is still staggering.
What Have We Learned
Video game physics is a complex field where developers must find a balance between realism and the compromises set by computational limitations. Finding shortcuts and relying on physics engines allows programmers to mimic real-world physics quickly and efficiently so that they can focus on more critical aspects of the game like the mechanics.
The bottom line is to make it fun. Realism takes a backseat to engaging gameplay. This is not to say that game physics is optional. On the contrary, designers must employ it in one form or another, or else the game will be chaotic with no intuitive rules. They can also bend the natural laws to make gameplay more fun and rewarding, such as including the ability to double jump.
If you are interested in the more technical points of video game physics and the way that game makers employ physics engines, there are several resources to get your started. Check out the physics section in the Unity manual or the Lumberyard tutorials. We may also cover the topic in more depth in a future article.
In the meantime, it may be fun to think about the things we have discussed as you play your next video game. Just like we explained how 3D rendering works in video games, can you spot shortcuts developers have used or find innovative ways that they employed physics in a manner that enhances gameplay? Give it a go and let us know.