Game Development Reference
In-Depth Information
3.3 Holding and releasing objects
It is necessary sometimes to give the player the ability to move objects around the scene, so
he can stack some boxes to access a high place, or remove some obstacles off the way, and
so on. Moving objects can be accomplished in different ways. For example, the player can
push objects by moving towards them, or he can use some super powers or devices to hold
objects (recall, for example, the gravity gun in Half-life 2). In this section, we are going
to make use of relations between objects to implement a mechanism that allows the player
to hold some objects, move while holding them, and release/discard these objects at any
position.
In this section, I am going to reuse first person input system we have developed in section
2.4. What we are going to do is to make the player able to hold the boxes and release them
by pressing E key. The scene we are going to use can be found in scene9 in the accom-
panying project. We need two scripts to apply holding/releasing mechanism. The first script
is Holdable , which we are going to add to all objects that can be hold by the player. This
script is shown in Listing 33, and it is an empty script that has only a radius for checking
distance with the holder. In our scene, we have to add this script to the boxes. It is a better
idea always to make a prefab of a holdable box and add copies of it to the scene.
Search WWH ::




Custom Search