Game Development Reference
In-Depth Information
How it works...
The
Trigger
class has a fairly simple functionality. It will wait for something to call its
trigger
method.
When this happens, it will either trigger all the connected ScriptObjects immediately or if a
delay is set, it will start counting until the time has passed and then execute the trigger.
Once this is done, it will be set up so it can be triggered again.
The
ScriptAppState
state is a convenient way to control the scripts. Since the
Ap-
pState
is either disabled or not attached to the
stateManager
, no call to
update
in
ScripObjects
is made. This way, we can easily disable all the scripting if we want to.
To create a working example with
Trigger
, we extended it into a class called
Enter-
ableTrigger
. The idea with the
EnterableTrigger
class was that if any of the
supplied actor spatials enter its
BoundingVolume
instance, then it should trigger
whatever is connected to it.
The basic
Trigger
method doesn't have the need for a position as it is a purely logical
object. The
EnterableTrigger
object, however, has to have a relation to the physical
space as it needs to know when one of the actors has entered its
BoundingVolume
in-
stance.
This is true for
SpawnTarget
as well, which in addition to a location should have a rota-
tion, to rotate a potential enemy in a certain direction. Spawning characters or items in
games is commonly used to control the gameplay flow and save some performance. The
SpawnTarget
option allows this kind of control by adding new spatials only when
triggered.
The strategy for how to perform spawning might differ depending on the implementation
but the way described here assumes it involves attaching the target
Spatial
to the main
node tree, which would generally activate its update method and controls.
Likewise, the
rootNode
of the scene graph is not necessarily the best choice to attach the
target to and depends a lot on the game architecture. It could be any
Spatial
.
Lastly, in this recipe, we created a
Pickup
object, which is very common in many games.
These can be anything from items that increase health instantly or weapons or other equip-