Sliding Joints

In depth learning on Scene Configuration can be found in this course in Motive Academy.

Overview

This article describes how you can implement Motive’s premade Sliding Joint component to connect 3D Assets and have them interact as if they were connected on rails. With only a few minor changes made in Unity, this functionality allows for easy and fast interaction that can be used in conjunction with other Motive premade features such as, VR Attachable, VR Attachable Receiver and VR Grabbable. After that, we will cover how we can check object states related to sliding objects in order to trigger events on Storyflow.

Video Walkthrough

Setup - Unity SDK

  1. Open your Unity project and in the scene Hierarchy window select World > Example Assets > Props > Workbench > Workbench_LOD0 > Bench Top

  2. Under the Mesh Collider component turn Is Trigger to off

  3. Scroll down to the bottom of the Inspector window and select Add Component > (Type in “Rigidbody”) > Rigidbody

  4. In the Rigidbody component toggle Use Gravity to off

  5. Toggle Is Kinematic to on

  6. Then in the Hierarchy window select World > Example Assets > Props > Workbench > Stud > Stud

  7. In the Rigidbody component toggle Use Gravity to off

  8. Toggle Is Kinematic to on

  9. Set your Collision Detection to Discrete

  10. In the Mesh Collider component, toggle Is Trigger to off

  11. Right-click on Stud in the Hierarchy window and select Motive > Make Grabbable

  12. Scroll down to the new Mesh Collider component and delete it by selecting the *Three dots* on the top right of the component, then select Remove Component

  13. In the new VR Grabbale component, make sure that Allow Distance Grab is toggled off

  14. In the Snap Position and Snap Orientation dropdown menus, make sure both values are set to “Never”

  15. Toggle Track Orientation to off

  16. Set Release Behaviour to Leave In Place

  17. Then change Move Mode to Physics

  18. While you are still in the Stud Inspector window scroll down to the bottom and select Add Component > (Type in “String State Setter”) > String State Setter

  19. In the State textbox type Plank Position

  20. Back in the Hierarchy window right-click on Stud and select Motive > Joints > Add Sliding Joint

  21. In the new Sliding Joint component under Axis change the X value to 0 and set the Y value to 1

  22. Under Secondary Axis set the X value to 1 and the Y value to 0

  23. Next, select the *Target* icon for the Connected Rigidbody area and then select Bench Top

  24. Then, toggle Limit Motion to On

  25. In the Lower Limit text area type as -0.2 and for the Upper Limit type as 0.4

  26. Expand the Upper Stop dropdown menu and Under Limit Threshold type 0.2

  27. Next in the In Limit() area hit the + icon then drag Stud from your Hierarchy window into the box that reads None (Object)

  28. Then, expand the No Function dropdown menu and select StringStateSetter > SetState (String)

  29. In the *Newly Created Textbox* type Outside

  30. Expand the Lower Stop dropdown menu and under Limit Threshold type to 0.1

  31. Next in the In Limit() area hit the + icon then drag Stud from your Hierarchy window into the box that reads None (Object)

  32. Then, expand the No Function dropdown menu and select StringStateSetter > SetState (String)

  33. In the *Newly Created Textbox* type Inside

  34. Save the Scene

Setup - Storyflow

Create the Enum

  1. Select the *Three Bullet List* icon on the right side of the screen (Reference Image Below)

  2. Next, select New Enum Name and type Plank Position

  3. After that, hit the > left of where it reads Plank Position and then select New Enum Item Name then type Inside

  4. Do this a second time but type Outside

Set up the Catalog

  1. Open Storyflow and select the Catalogs tab

  2. If you do not have a “Named Object” Catalog already, select Create > Select Type > Named Object > (Type a name) > Create

  3. Open your “Named Object“ Catalog then select + > Named Anchor > (Type in “Stud”) > Save

  4. Save the Catalog

  5. If you do not have a “Behaviour Model” Catalog already, select Create > Select Type > Behaviour Model > (Type a name) > Create

  6. Open your “Behaviour Mode“ Catalog then select + > Behaviour Model > (Type in “Stud Behaviour Model”)

  7. Then select States + > (Type in Plank Position)

  8. Expand the Primitive dropdown menu and change it to Enum

  9. After that, expand the NOT SET dropdown menu and select Plank Position

  10. Save the Catalog

Scripting

  1. Open the Scenarios tab and Create a New Script

  2. Open the new Script

  3. Under Resources on the right side of the screen click and drag the Scene Object Resource into
    the grey area in the center of the screen

  4. Select Object + > (Your Named Object catalog) > Stud

  5. In the same grey area mentioned before, drag and drop in the Behaviour Model Resource

  6. Select Targets + > Stud

  7. Then, select Behaviour Model > (Your Behaviour Model catalog) > Stud Behaviour Model

  8. Select the + icon attached to the “Main Frame” on the left side of the screen to create a new Frame

  9. Select the newly created Frame and in the same grey area mentioned before, drag and drop in the
    Set Object State Resource

  10. Select World Objects + > Stud

  11. Then, select Behaviour Model > (Your Behaviour Model catalog) > Stud Behaviour Model

  12. Select CHOOSE STATE > Plank Position > Compare +

  13. In the new Value dropdown list select Outside

  14. Next, select the blue + icon on the bottom right of the Set Object State resource, scroll down the list that appears and select Close

    1. In the newly created frame, add the Notification Resource and under Message type Outside

  15. Again, select the + icon attached to the Main Frame on the left side of the screen

  16. Select the newly created Frame and in the same grey area mentioned before, drag and drop in the
    Set Object State Resource

  17. Select World Objects + > Stud

  18. Then, select Behaviour Model > (Your Behaviour Model catalog) > Stud Behaviour Model

  19. Select CHOOSE STATE > Plank Position > Compare +

  20. In the new Value dropdown list select Inside

  21. Next, select the blue + icon on the bottom right of the Set Object State resource, scroll down the list that appears and select Close

  22. In the newly created Frame, add the Notification Resource and under Message type Inside

  23. Select Save on the top left of the screen

  24. Create a Scenario, if there isn’t one already

  25. Link the Script you created to the Scenario

 

You can now open your Unity Project. Select the newly created Scenario, once it has loaded you should be able to grasp the Stud from the workbench, slide it to the left, and read your new Notifications!

Related Articles