Game Development Reference
In-Depth Information
As you see, this is a relatively large component with lots of options to deal with. However, we
are interested in some options that allow us to get the desired functionality.
Anchor
and
Axis
values specify the position and direction of the rotation axis. Since we are making a rotating
door, the axis need to be on the side. If you consider z size of the door as its thickness, and
x size of the door as its width, then the position of the rotation axis is (0.5, 0, 0), which
is the right end of the door. Similarly, the direction of this axis needs to be (0, 1, 0), so
that the axis goes along y axis. The second change we need is activating
Use Spring
, which
generates a force that returns the door to its original position when there are no external
forces affecting it. The related
Spring
and
Damper
values must be appropriately set, so they
are neither too strong nor too weak. The values you see in Illustration 78 have been config-
ured to be appropriate for the physics character we created in section 4.3. Finally, we have to
activate
Use Limits
, in order to set maximum and minimum degrees of door rotation. In this
case, we make a bi-directional rotating door that rotates 180 degrees. In other words, the
door can be pushed from both sides and rotates up to 90 degrees. You may add a physics
character with first person control to test the door.
Now we are going to lock this door and create a key. The player must posses this key
in order to open the door and pass through. The key is going to be collectable and, when
collected, is going to be added to the inventory box of the player. Therefore, we need a script
similar to
Collectable
script we have created earlier (Listing 26 page 76), in addition to
In-
ventoryBox
(Listing 29 page 79). For this latter script, we have to add a list to store the keys
that the player has. These keys are simply strings. The modified version of
InventoryBox
is
shown in Listing 61.