Overview
This article describes how to take a bottle with a cap attached. And, make it so both the cap and the bottle can be grabbed and moved around separately then reattached. The bottle and the cap will also be using gravity physics.
We will do this using four premade Motive SDK features.
VR Attachable
VR Attachable Receiver
VR Grabbable
Fixed Joint
Setup
For this example, we are starting with this relatively simple bottle and bottle cap prefab variant
First, we will right-click on the bottle in the Hierarchy window then select Motive > Make Grabbable
After that, right-click on the bottle again and select Motive > Make Attach Receiver
Next, when you expand the bottle in the Hierarchy window and right-click on the bottle cap, then select Motive > Make Grabbable
Next, back on the bottle cap, right-click and select Motive > Joints > Add Fixed Joint
Then, on the bottle cap, right-click and select Motive > Make Attachable
Finally, in the Inspector for the bottle cap, scroll to the bottom and select Add Component
Next, type in “Mesh Collider” and select Mesh Collider when it appears
NOTE: If there is already a Mesh Collider on the cap, there is no need to add a second
Once all the necessary components have been added. Now we will add grab anchors for both the cap as well as the bottle itself
Right-click on the bottle in the Hierarchy and select Create Empty
From there, you should be able to modify the Y Position value under the Transform component of the new empty object (Move it near the middle of the bottle lengthwise)
Next, select the bottle and then open the VR Grabbable drag your new empty object into the black box next to Grab Anchor that reads “None (Transform)”
Next, we will do the same thing for the cap of the bottle. Right-click on the cap and select Create Empty again
Once again, modify the new empty objects Y Position value under Transforms so that it is somewhere near the center of the bottle cap
Then select the cap and once again, under VR Grabbable, drag the new empty object into the same Grab Anchor box
Now, we must configure all of the newly attached components to replicate the behaviours shown in the video above
Firstly, the bottle will be configured. Select it in the Hierarchy, then
Expand the Rigidbody component and make sure that Use Gravity and Is Kinematic are toggled to on
Expand the VR Attacahable Receiver and select the Target icon featured on the box next to Joint; the box should read “None (Base Joint). Once the new window opens, select the cap joint
Expand the VR Grabbable component
Set Snap Position to Always
Set Snape Orientation to Always
Next, the cap should be configured. First, select it in the Hierarchy, then
Expand the Box Collider and set Is Trigger to On
Expand the Rigidbody
Toggle Use Gravity to On
Toggle Is Kinematic to Off
Expand the Mesh Collider and set Convex to On
Expand the VR Attachable
Then expand Attached Grab Settings
Toggle Working Surfaces Only to On
Set Release Behaviour to Use Physics
Next, expand Detached Grab Settings
Toggle Working Surfaces Only to On
Set Release Behaviour to Use Physics
Select the Target icon featured on the box next to Attached To; the box should read “None (Base Joint). Once the new window opens, select the bottle receiver
Expand the VR Grabbable
Toggle Allow Distance Grab to On
Finally, if you take your prefab variant and drop it into a VR scene, you should be able to use the bottle and cap the same way highlighted in the above video
Troubleshooting
If you are concerned about the release behaviour of your cap. Remember that the release behaviours you define in VR Grabbable will always be overwritten in VR Attachable.
However, not all values set in VR Grabbable are mutual between itself and VR Attachable.
If the bottle and cap behaviour is not what you see in the video, be sure to double-check your component configurations. Specific changes to other components can affect one another.
If you see that specific configurations change during runtime during playtime, do not be alarmed. For example, values like Collision Detection, Use Gravity, etc., will all change when an object is dropped, grabbed, etc.
Do not treat Mesh Colliders and Box Colliders the same. For example, if you set Is Trigger to On in your mesh collider instead of the Box Collider on the bottle cap, the cap can be reattached but not nearly as fluidly.
Feel free to ignore prompts similar to these found at the top of VR Grabbable and Fixed Joint components. They are redundant.