Physics in games has become quite popular in recent years. It is not like older games do not have any physics, but recently many shooter games have complex physic systems that are only possible through the immense increase in computing power and multi-core systems. Even hardware PPUs (physics processing units) are available today, similar to GPUs that just handle graphics. These processors are just for calculating physics.
The games that use physics the most are first-person shooters, especially if you have a lot of freedom and allow the player to walk around freely and interact with the scenery. One of the most popular games that used a lot of innovative physics techniques and also involved physics in the game play and mission design was Half-Life 2, which came out at the end of 2004.
Half-Life 2 uses the commercial physics engine Havok internally, but there are several other physics frameworks, which are discussed in a short while. Sadly none of them will work on the Xbox 360 with the XNA Framework because they all use unmanaged code, which is not allowed on the Xbox 360 when you develop games with XNA. On the PC you can use whatever you like, and this chapter discusses which framework might be the best to use right now. The Racing Game you are currently developing will not make use of any advanced physics framework for that reason and because it is a lot of work implementing and testing such a powerful framework, aside from the fact that most of them cost a lot of money to license. In Half-Life 2 the engineers spent several years tweaking and fine-tuning the physics until they were pleased with the result.
Physics always comes along with some heavy mathematics. It is certainly possible to use a physics framework or apply a simple formula like the famous F = m * a without knowing much about physics or math, but as soon as you want to develop your own physics system for your game, you will need at least a basic understanding of Newton’s laws of motion. Having a physics formula book nearby or at least Google at your fingertips for help is also a good idea. Figure 13-1 shows a typical example of a physics problem involving several objects, transmitting forces, gravity, and so on.
When you talk about physics you just have to mention Isaac Newton, the apple, and the tree. You know the story. Physics has evolved quite a bit since then and there are many theories about the extremely small world of atoms, quarks, electrons, and so on and of course the macro cosmos, the solar system, stars and planets, and so on. But for most games you are happy to use just a bunch of simple physics formulas to help you accelerate and decelerate objects. It is just not practical to work on a smaller scope due to limited processing power and because it just has to look good, you don’t need every virtual atom to behave like in the real world.
While formulas like Newton’s laws of motion will be heavily used, you are going to spend most of the time with collision issues, just like for the Rocket Commander game from Chapter 8. At least physics are fun and thanks to unit testing you can quickly try out things until they work, but be aware - you can spend a lot of time with physics and it is hard to see the results of your work if the world of your game does not allow much interaction. It is nice to have real physics for a puzzle game, but if all you can do is click on objects to be removed, you really don’t need a complex physics engine. Just fake it!