Using Attachables and Fixed Joints alongside VR Grabbable
In depth learning on Attachable Basics is found in this course in Motive Academy.
- 1 Overview
- 1.1 Setup
- 1.2 Configuration
- 1.3 Troubleshooting
- 2 Related Articles
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:
Right-click on the bottle in the Hierarchy window
Select Motive > Make Grabbable
Right-click on the bottle again
Select Motive > Make Attach Receiver
Expand the bottle in the Hierarchy window and right-click on the bottle cap
Select Motive > Make Grabbable
Back on the bottle cap, right-click and select Motive > Joints > Add Fixed Joint
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
Type in Mesh Collider
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
Configuration
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
Select Create Empty
Modify the Y Position value under the Transform component of the new empty object (Move it near the middle of the bottle lengthwise)
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)”
Do the same thing for the cap of the bottle. Right-click on the cap and select Create Empty again
Modify the new empty objects Y Position value under Transforms so that it is somewhere near the center of the bottle cap
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.
Select the bottle in the Hierarchy
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
Select the cap in the Hierarchy
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
Expand Attached Grab Settings
Toggle Working Surfaces Only to On
Set Release Behaviour to Use Physics
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).
Select the bottle receiver
Expand the VR Grabbable
Toggle Allow Distance Grab to On
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.