Chapter 23. Shooting a Gun

It's an unfortunate fact that shooting (and being shot) is a major part of many types of games. Exact percentages are hard to come by, but I've seen figures which indicate that perhaps 40 percent of the top-selling console games involve shooting, rising to 50 percent for PC games. My own feeling is that the percentages are much higher.

I'm writing this as Christmas 2004 approaches, and the top action games for the PC include Half-Life 2, Doom 3, Medal of Honor: Pacific Assault, The Lord of the Rings: Battle For Middle Earth, Warhammer 40,000: Dawn of War, World of Warcraft, and so on. Where's the peace and harmony gone? Santa better have some serious armor on his sleigh this Yuletide.

Action games can be categorized into third person and first person. Third-person games frequently utilize a viewpoint slightly above and behind the main character as in Splinter Cell and Hitman. First-person games put the gun in your hand, with a viewpoint linked to the gun, as in Doom and Half-Life.

This chapter looks at how to get an object in the scene to shoot. This is a prerequisite for third person games and, of course, is needed in first person games when the enemy fires back. Chapter 24 is about first person shooting, where the shot comes from your own gun.

The Shooter3D application contains a gun (a cone mounted on a cylinder) which fires a laser beam at a point on the checkered floor clicked on by the user. The flight of the laser beam (a red cylinder) is accompanied ...

Get Killer Game Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.