Recipe 4 Unity6 - RosoVRgarden/VRgarden-tutorials GitHub Wiki

VR recipe 4: Door and Cabinet Using Unity Physics

The cabinet is a simple object that shows the use of hinges (doors) and configurable joints (drawers, sliding doors). Find the cabinet in the hierarchy.

  1. Once you have imported the cabinet, add <XR Grab Interactable> component on the door to get started. It includes a <Rigidbody>. Make sure that there is a collider attached to your object. It’s also a good idea to have handle, make sure that it is a child of the door, has a collider and not static as it moves.

In the <XR Grab Interactable>, select Velocity Tracking in the Movement type (see point 4) as it tracks the movement with with hinges using the physics engine. Finally, you need to add a collider in Colliders (change size to 1) and drag the Door handle into the Element 0 as it is the object that connects to your hand.

  1. Next step is to select the door and add a <Hinge Joint> component. Click on the Edit Angular Limit to select where it is attached to (where would you normally put the hinges). Click use Limits to select what angles they should be open to (the limit is -180° to 180° but 0° to 90° makes more sense). The Axis is the plane on which your object is rotating (X axis is set to 1 to rotate around the X axis). The Anchor can be changed if Unity hasn’t found the edge of your door on its own. Use Spring option allows your to add some Damper and make the door feel heavier.

  1. The drawer is a little bit more tricky as it is a sliding mechanism (like sliding doors). You will also need to add <XR Grab Interactable> component to get started and select Velocity Tracking in the Movement type as it tracks the movement with more precision (using the data from the physics engine).You can simulate a drawer using the <Configurable Joints> component. then change the X Motion (if you are moving in the X axis) to limited and others to locked if you want to move in one axis only. The next things is the Linear Limit which stops you moving the drawer (0.4 in this case), moving it according to your requirements.

  1. More: the Movement Type are important in virtual reality as they are about the optimisation of resources in your project. Velocity Tracking is for grabables objects that require more precision such as doors that requires physics simulation, kinematic offers a good simulation but is less precise than the previous. Finally, instantaneous is the least precise as it even moves through colliders.

⚠️ **GitHub.com Fallback** ⚠️