Previous Tutorial: Sensation Source Playback
Next tutorial: Sensation Core Library and Blocks
- Setting up the example
- The Touch Block scene in detail
- Worked Example – Adding more shapes
- Bubbles Demo
In this tutorial we add “sensation” to a simple, moving shape. By adding the Leap Motion® camera module, we show how that sensation can be triggered when a hand interacts with it, thereby providing haptic feedback.
We present a simple example – Touch Block – with all the steps needed, including adding Leap Motion® assets, to get up and running. We finish by looking at a more complex but similar Bubbles example.
Setting up the example
- Download or clone the UnityExamples Project found on our Unity Examples Github Repo
- In Unity, open the UnityExamples project
- Open the TouchBlock scene from the project’s Examples folder
- Import the Ultrahaptics Core Asset as shown in the UCA’s Quick Start Guide.
- To add tracking to Unity with the Leap Motion® camera module, we must add Leap Motion SDK and Leap Motion Unity asset.
The scene has a TrackingOrigin game object. Add the Leap Motion prefabs as children of this.
- Download and Install Leap Motion Orion 4.0.0 SDK,
- Download Leap Motion Unity Core Assets 4.4.0,
- Import the Leap Motion Unity Core Asset into your Unity project,
- From LeapMotion/Core/Prefab, add the LeapHandController prefab to your Scene,
- In the LeapHandController Hand Model Manager component, type ‘2’ into the Model Pool > Size field.
- For each entry, ensure both “Is Enabled” boxes are checked then and
- add the listed Leap Motion prefab objects to the Graphics and Physics Hands sections:
- HandModelsNonHuman/Capsule Hand Left
- HandModelsNonHuman/Capsule Hand Right
Your LeapHandController game object should look like the image shown. The same procedure should be used in any lesson where we will need to add the Leap Motion assets.
Finally, connect your array and Leap Motion camera module. Ensure the Leap Motion service is in a tracking state.
Play the scene. You should be able to see hand models move as you interact with the scene, feeling the sensation as the hand intersects the moving box. Select the Gizmos button to visualise the haptic path as you touch the box.
The Touch Block scene in detail
The TouchBlock scene includes the following Unity game objects:
- UltrahapticsKit (the TrackingOrigin child of this GameObject is where your Leap Motion prefab should be added)
- HapticCube – creates the cube, its movement and hosts and triggers sensation sources
- Base – indicates the bottom of the interaction zone
As well as the Leap Motion prefabs, the TrackingOrigin (a child of the UltrahapticsKit) has a “Leap Data Source” component. This encapsulates the Leap Motion data for the UCA. Alongside the components of the UltrahapticsKit prefab, it is part of how the UCA manages tracking. We’ll look at this in more detail later, but for now, just assume it does its thing.
Attaching Sensation to a Game Object
Let’s look at how we trigger the sensation in more detail. The HapticCube has a number of components, listed in the inspector window.
At its heart, Haptic Cube is an animated box with a Sensation Source component. The sensation block is set to use the “Square” sensation. The HapticCube has a child object called CubeTransform, whose transform component controls the sensation position, size, and orientation.
Each of the four coordinates of the square sensation is given as a fraction of the Transform’s Scale property.
Haptic Trigger Region
The HapticCube’s child object CubeTransform has a box collider attached. This is used to enable and disable the running state of the sensation through a script component called Haptic Trigger Region.
The Haptic Trigger Region allows us to perform some action on the collision events. On Enter and On Exit event handlers set the Sensation Source’s Running property so that sensation is triggered as the hand “touches” the shape.
Worked Example – Adding more shapes
Let us now add a second shape to our scene.
1. Add a 3D Sphere game object to your scene. Right-click in the scene hierarchy and select “Sphere” from the list of 3D objects and set as a trigger collider.
2. Move the Sphere somewhere out of the way of the cube’s path, e.g. 20cm above the array and 5cm off centre. Give it a radius of 3cm (Scale x, y and z = 0.03).
3. Add the necessary components – Sensation Source and Haptic Trigger Region – to the Sphere game object to trigger sensation when your hand collides with it (no need to create a child object this time):
4. Set the Sensation Block to “CircleSensation” and drag the Transform to Sensation Source’s Transform field. Set the radius property to 0.5.
5. Run and play… we should see the circle sensation trigger as we collide with the sphere.
Remember, you can view the sensation path by enabling Gizmos.
Alongside the Touch Block example, you will see the Bubbles Demo. Open the Bubbles scene and, as above, add the Leap Motion asset and prefab, the Ultrahaptics Core Assets, as a child of the UltrahapticsKit/TrackingOrigin GameObject
When you run the scene, you should see the bubbles rise from the surface of the array and popping as they collide with your hand. You should feel the sensation of each bubble bursting!
Have a look at the various components of the scene to see how it works. Apart from the mechanics of how the bubbles are generated, the interaction of the bubbles and the hand is similar to that used in the TouchBlock scene. It uses a number of specific scripts to manage the bubbles’ size and appearance.
Next tutorial: Sensation Core Library and Blocks