HoloLens Dev 101: How to Explore the Power of Spatial Audio Using Hotspots
When making a convincing mixed reality experience, audio consideration is a must. Great audio can transport the HoloLens wearer to another place or time, help navigate 3D interfaces, or blur the lines of what is real and what is a hologram. Using a location-based trigger (hotspot), we will dial up a fun example of how well spatial sound works with the HoloLens.
In this tutorial, we will be creating a spatialized audio object that revolves around a target object. You will be able to stay put and listen as the hologram travels the space around you, or move about and explore the changing audio freely.
In order to jump right in, you will need to first complete the User Location Hotspots tutorial. This tutorial also requires using a HoloToolkit version that incorporates the user input modules (I am using a version pulled from GitHub on April 2017).
Okay, we’ve got the routine paperwork out of the way. Let’s start building!
Let’s start by dragging the InputManager prefab from HoloToolkit -> Input -> Prefabs folder in the Project window into the top level of the Hierarchy window. Let’s also do the same for the cursor by dragging in the DefaultCursor found in the HoloToolkit -> Input -> Prefabs -> Cursor folder. Adding both of these prefabs quickly gets our app ready to handle gestures.
A quick side note, if you use the Holographic Remoting Player to remote to your HoloLens while in Unity (I hope you are!), you will need to check the Allow HDR box on the Camera component of the HoloLensCamera GameObject. Otherwise, you’ll see a blank screen on your HoloLens when you play the scene in Unity.
Ideally, we want to be able to move our hotspot with the tap-and-hold gesture. However, we only want that to happen when we are gazing at the cube; not its oversized hotspot collider. We need to make a few changes to achieve this.
Highlight the Cube, then in the Inspector, deselect the Mesh Renderer component. Use the Layer drop-down and select “Ignore Raycast.” Since this invisible object is now just being used to trigger events, we don’t want our gaze to be intercepted by its collider. Not only is it disorienting for the user, but it will also sabotage our gesture action we build later in this step.
Next, create a 3D Object -> Cube. Rename this “Handle.” In the Hierarchy, make this object a child of the existing Cube object. Select Handle, and using the gear menu, “Reset” its Transform. Also, ensure its Layer is still set to “Default.”
Attach the “HandDraggable” HoloToolkit script component to our Handle. Do this by clicking “Add Component” while inspecting our Handle. Type in “drag” and press Enter. If we were to test now, we’d have the problem of the Handle moving, but our parent and its collider staying…