Demo: Grab

In this tutorial, we will create a basic Grab interaction. When grabbing a cube, it will play an audio.
Image

You will find this example already executed in the Project panel under Assets > SpatialStories > Example Scenes > DemosGettingStartedVR > DemoGrab.

This tutorial is using the Audio action. To know more about it, check our Audio tutorial under the Action tutorials.

Setting up your scene

  • Set up a scene with a floor and an Interactive Camera. Follow this tutorial if needed.
Image
Image

Adding the Grab Condition

First, we need to declare that our Cube (IO) can be grabbed.
  • Select 'Cube (IO)'. In the Inspector panel, look for 'Manipulation Modes' under 'Interactive Object Setup'. In the dropdown menu, select GRAB.
    You will notice that two variables - 'Grab Distance' and 'Attraction Grab' - will appear under 'Manipulation Mode'. This determines if you want your Interactive Object, in our case Cube (IO), to be grabbed from a distance or not. If you don’t want the user to be able to grab from a distance, change the value of 'Grab Distance' to 0.
    For this tutorial, keep the values as is, i.e. we will be able to grab the Cube (IO) from a distance.
Image

Play Audio when Grabbed

Now, we want to create an Interaction that will play an Audio when Cube (IO) is grabbed.
  • In the Hierarchy panel, expand 'Cube (IO)', expand 'Interactions', and duplicate the first Interaction.
    It is advised to always keep one original interaction and duplicate it whenever you want to create a new one.
  • Rename the duplicated 'Interaction (1)' into Play when grabbed.
    Using descriptive names for your interactions will make things easier, especially in case of complex experiences.
  • Select 'Play when grabbed'. In the Inspector panel, under CONDITIONS, check Grab. In the first dropdown menu, select BOTH. You will notice that GRAB is already selected in the second dropdown menu, and Cube (IO) is the target object.
    This means that the condition will be met when either or both hand(s) touch the cube's Hand Hover collider, which you can find if you expand Cube (IO) in the Hierarchy panel.
Image
By default our interactions happen only once. In order for this interaction to reload, we need to set it up!
  • In the Inspector panel, go to the RELOAD section. Check Reload and change its value from MANUAL_ONLY to INFINITE
Image

Now let’s create actions so that audio will be activated when this condition is met.

  • With 'Play when grabbed' selected, scroll down the Inspector panel until you reach ACTIONS. Look for Audio in the 'Animation & Audio' section. In the dropdown menu select ACTIVATE.
Image
  • Under 'Audio Source', drag the audio Gong_2 to the target audio.
Image

You just learnt how to use Grab in SpatialStories. Congratulations!