Creating a sliding drawer 2

In the last tutorial, we made a drawer that can be opened and shut by dragging it with the mouse. But, drawers are only useful if there's anything in them - so now we'll add something inside. In keeping with using the Physics demo assets, we'll place a letter inside.

Find the Letter model within PhysicsDemo → Models → Letter and drag it into the scene. Don't make it a child object of the drawer - instead place it in the _SetGeometry folder. Position it inside the drawer - it'll be easier to do so if you temporarily disable the table model:

Add a Box Collider and Rigidbody to the Letter. To simplify calculations, uncheck Use Gravity and the following Freeze flags:

When testing the game, you'll find that the letter will behave erratically - soon clipping through the drawer. This is because the drawer's Sphere Collider is interfering with it. As stated earlier, the Sphere Collider must exist - but it doesn't necessarily need to live inside the drawer.

To remove the conflict between the letter and the Sphere Collider, we'll move the collider 1 unit away. Since the Track must be in the same place, we'll have to move that as well. Select both DrawerTrack and Drawer_Draggable, and move them 1 unit along the X-axis (or along whichever way is to the side of the drawer).

Then, select the drawer's two children, TableDrawer1 and Drawer_Collider, and move them back 1 unit, so that they're back where they started:

Now when you test it, the letter will behave itself better. You may need to tweak some of the physics settings, such as the letter's Box Collider's Size and Material, as well as it's Rigidbody's Mass, to perfect the behaviour.