Game Development Reference
In-Depth Information
How it works...
With this implementation, we handle most of the actual logic that happens when firing in-
side
InputAppState
. The
GameCharacterControl
class is left to keep control of
whether firing is possible or not. Some further work on this could have the character play
an animation and keep track of the ammunition.
The
Ray
object we're using is being fired out of the camera. This makes it easy to set both
the location and direction. This would be the case for a game in iron sights or sniper mode.
If you want to fire from the hip, for example, it would be slightly more complicated.
Rays are normally very fast. Using them can, however, become performance-demanding in
large game worlds with complex collision shapes. This is one reason for keeping track of
the items to be checked against in a list rather than using the whole
rootNode
. In other
cases, it's good to first filter down the list, maybe based on the distance from the player.
The
CollisionResults
class stores collisions between
spatial
or
ray
. It contains
a list of
CollisionResult
objects, which in turn has a number of useful methods for
determining where a collision has occurred and between what.