In this tutorial, you will learn how to use Interaction SDK locomotion interactions to teleport to a location on a NavMesh in your Unity scene using your hands or controllers. This takes advantage of the Unity Navigation system to quickly stablish which areas of your scene can be teleport-eligible. This guide assumes you have a scene set up with a camera rig configured for interactions and a NavMesh. If you do not have a camera rig set up, you can add one by following the instructions in the Create Comprehensive Rig guide.
Add a NavMesh Teleport Target
To teleport, you need to add a teleport interactable. To freely teleport to any location the player is allowed to navigate to within the scene, you can use a NavMesh as the target, which enables the user to teleport to any location on that NavMesh.
Right-click on the NavMesh object you want to use as a target and select Interaction SDK > Add Teleport Interaction. The Teleport wizard appears.
In the Teleport wizard, set the Interaction Type to NavMesh. This will set the selected NavMesh object as a target for teleportation.
Set the Walkable Area Name to the name of the area you want to use as a target. In this example, the NavMesh was set up using the default Walkable area name so that is the name used here.
If you want to further customize the interaction, adjust the interaction’s settings in the wizard. For details on the available options, please see the Teleport Quick Action documentation.
Select Create. The wizard automatically adds the required components for the interaction to the GameObject. It also adds components to the camera rig if those components weren’t already there.
Open the Link desktop application on your computer.
Put on your headset, and, when prompted, enable Link.
On your development machine, in Unity Editor, select the Play button.
Tap your thumb against the side of the index or press the joystick forward on your controllers. A ray is emitted from your hands or controllers. Aim it at the teleportable area designated by the NavMesh and either tap your thumb again (if using hands) or release the joystick (if using controllers), to teleport to that location.
Test your Interaction
Build your project into an .apk to test your project.
Make sure your headset is connected to your development machine.
In Unity Editor, select File > Build Settings. Add your scene to the Scenes In Build list by dragging it from the Project panel or clicking Add Open Scenes.
Click Build and Run to generate an .apk and run it on your headset. In the File Explorer that opens, select a location to save the .apk to and give it a name. The build process may take a few minutes.
Tap your thumb against the side of the index or press the joystick forward on your controllers. A ray is emitted from your hands or controllers. Aim it at the teleportable area designated by the NavMesh and either tap your thumb again (if using hands) or release the joystick (if using controllers), to teleport to that location.