Game Development Reference
In-Depth Information
Getting ready
This example will be based on
GameCharacterControl
and
InputAppState
from
the
Creating a reusable character control
and
Attaching an input AppState object
recipes
of this chapter, respectively. Familiarity with the recipes is beneficial. Further, we'll use the
Ray
class in combination with
CollisionResults
to check whether the bullet has hit
anything or not.
Rays can be imagined as infinite lines and are very common in game development. This is
a fast way of detecting intersections with game objects and is thus suitable for instant fir-
ing. The targets might consist of any kind of
spatial
. In this case, it's a bunch of spheres
generated by the recipe's test class.
We will let the
InputAppState
class handle the firing logic, and the
GameCharac-
terControl
class will keep track of cool down time of the weapon, or how long it takes
between each shot. The reason we don't keep everything in
AppState
is that this way, the
class can be used for things other than the player's character.