Interaction with Cabinet ( Door ) in VR - Unity3d

 The Cabinet

We have a Cabinet object prefab consisting of a variety of materials as seen in the image below:


The Door

The Door has a child object called door handle.

We can add an XR Grab Interactable script onto the door and set the door handle as a collider, meaning that we can only grab the door handle to interact with the object.


Note: We can create a new layer called Grab (no ray) to prevent our ray cast from interacting with the door handle. On the XR Ray Interactor, we can change the mask to only show if a UI or grab is hovered. This case would be useful if you want a more realistic door handle grab. If you have a separate layer, remember to go onto project settings and disable Grab (no ray) with body collision under the layer collision matrix.

Now we're able to grab the door but we want to be able to make the door revolve around the joints.

First, change the movement type of the door to Velocity Tracking ( see movement type blog to see why we want to use velocity tracking) but in summary, because it adds physics to the door so you can fling the door open and close.

Add a Hinge Joint component onto the door and by pressing the icon Edit Angular Limits, choose where you want the door to revolve around. For this case, you can see in the image below where the join was selected. Next, because we don't want the join to revolve forever, we can select the Use Limits option, and then drag the limit to however far we want the door to rotate. 


In addition, the hinge joint has an option called damper, which can damper the speed at which the joint object moves.