Drawers are a nice way to add depth to objects in your game such as furniture. There are 3 example pieces of furniture included with the asset. demoBasicDesk, demoComplexDesk, and demoDresser_A.
All drawers have a common set of parts that behave help it function. Some of these parts are optional, and some are not.
Drawer Mesh | This is the visible "drawer box bit" that acts as the main main drawer body. |
Drawer Pull Mesh(es) | The part of the drawer the player looks at when interacting with the drawer. |
Sliding Part | This houses all the moving parts of any drawer (such as the drawer mesh, drawer pulls(s), colliders, and other objects) |
Drawer Pull Interaction(s) (uses FPEInteractableActivateScript component) | These are the Activation type objects that allow the player to open and close the drawer. It's a good idea to align these with the visible drawer pull mesh(es), and perhaps make them even larger. |
Hit Helpers (uses FPEDoorAndDrawerHitHelper component) | Optional child objects that are used to detect when a drawer should stop moving. Useful for ensuring large or tall objects placed in a drawer don't break things. |
Drawer Colliders | These keep Pickups and other stuff inside the drawer. For best results, use a handful of Box Colliders rather than a Mesh Collider. |
Drawer Contents Grabber | A special trigger volume that makes objects in the drawer stick to it when the drawer moves. |
All drawers have a shared set of Inspector Fields.
Start Internally Locked | If true, this means the drawer will start internally locked, and require specificed inventory item to act as a key to unlock it. |
Required Key Type | The type of inventory item required to unlock an internally locked door. |
Start Externally Locked | If true, the drawer will start externally locked. This means an external object such as a security system will need to unlock it before it can be opened. |
Start Opened | If true, the drawer will start in an Open state. You will also need to visually move the sliding part of the drawer to reflect this state. Good for cases where you want a drawer to be opened a little already to guide the player to it, or have an object visibly sticking out of it. |
Stop If Drawer Hits Something | If true, the drawer will use its Hit Helpers to stop when it hits another object such as the player or blocking physics object like a Pickup or large object in the drawer. |
Drawer Pull Handle Interaction Text Overrides | These interaction strings are assigned to the door handle(s) when different actions take place. |
Play Sounds | If true, your drawer will make sounds during various actions and events. |
Drawer | These are the various sound banks that will be used to make sound effects if Play Sounds is true. |
Slide Distance | How far the drawer slides |
Slide Open Time | How long it takes for the drawer to slide either open or closed |
Drawer Slide Snap Distance | The distance considered to be "close enough" for the drawer to snap closed or open. Smaller drawers need smaller values. |
Auto Move Player To Safe Zone | If true, Player will be automatically moved into safe zone so the drawer will be less likely to hit them. |
This asset comes with some example furniture prefabs with pre configured drawers: demoBasicDesk, demoComplexDesk, and demoDresser_A. To use them, simply drag them into your scene. If using the _Locked variant, ensure the player has access to the required key (default is demoSimpleKey.prefab). If using the _ExternallyLocked variant, ensure there is something such as the demoSecuritySystem prefab included so that the door can be externally unlocked. Run the scene and use the doors. You're done.
You can also take the drawer child objects from these prefabs and stick them into whatever furniture you want.
To create a customized Drawer from scratch, follow these steps:
Sometimes, it is hard to gauge the relative size of a drawer with respect to the player. As a result, drawers are hard to interact with. For best results, ensure that your furniture is designed in a way that facilitates easy drawer placement and use. By default, using Safe Zones will ensure a smooth gameplay experience. But, you can just let the drawer push the player, though that can be a little jarring sometimes. You can also do things to prevent the drawer from hitting the player at all, such as adding a Kinematic Rigidbody with Locked Rotation to the drawer's SlidingPart\Collider child object. This allows the player to "get closer" to the drawer, but can be a problem for really deep drawers and have other knock-on effects, so use with caution.
See below for examples of various methods in action:
Default Behaviour: Drawer gently and smoothly moves player out of the way (Best overall)
Drawer stops when it hits the player (Realistic, but can be a little cumbersome)
Drawer pushes player out of the way using physics collisions (Can be jarring)
Sometimes, tall objects will be put in drawers. The default configuration for most of the demo drawers is to basically stop moving if anything is in the way. However, you may want to lean on the physics engine a bit more to allow for the player to cram stuff in drawers and try to close them anyway. To avoid a "stuck drawer" feeling when this happens, you can play with the thickness of the "CloseHitHelper" child object of the drawer. Below is a more physics-driven close operation with a tall test object.
To achieve this new result, the CloseHitHelper was simply made thinner, as shown below:
Try experimenting with your own drawers to see what kinds of results you get for the objects you have in your game.
Drawers are meant to be set up as standalone prefabs. When placing drawers into furniture or other objects, you can optionally make them children of the furniture. For best results, model your furniture and drawers in a way that allows you to export the drawer meshes as separate model files. Similarly, you can leave out the drawer pull from the main drawer model, and create it separately. This will allow for more flexible customization and reuse between drawers and drawer pulls.
When you want any drawer to start locked from an external source (e.g. security system), you must check the "Start Externally Locked" checkbox in the Inspector. Most importantly, you must also include another object such as the included demoSecuritySystem prefab, and assign it to unlock your drawer. Externally locked drawers can only be unlocked from External systems. Otherwise, they will be locked forever! :)