Teleport

Introduction

The Teleport is a common used feature in the VR environment and we will introduce how to implement the feature here.

Resources

There are foure prefabs used in the sample demonstrated below: WaveVR, ControllerLoader, InputModuleManager and WaveVRButtons.

All prefabs are located in Assets/WaveVR/Prefabs

Sample

  1. After reading the document How to Change Head Location, you will know how to change the head location in the VR environment.

    Assume that you have a sample scene, you will need to put the WaveVR, ControllerLoader and InputModuleManager prefabs under a parent object (e.g. TeleportRoot).

    _images/Teleport01.png
  2. Drag the WaveVRButtons prefab into the sample scene for using the button events.

    _images/Teleport02.png
  3. You will need to add a new script (e.g. Teleport) in the TeleportRoot object to set up the location.

    Because of the origin of the head is (0, 0, 0), we assume the body height is 1.75m here in this sample.

    _images/Teleport03.png
  4. In the code, get the head instance in the Start function:

// Use this for initialization
private GameObject head = null;
void Start () {
    if (head == null && WaveVR_Render.Instance != null)
    {
        head = WaveVR_Render.Instance.gameObject;
    }
}
  1. Get the teleport target location when receiving the button pressed event of the Dominant Touchpad key in the Update function:
// Update is called once per frame
private Vector3 targetLocation = Vector3.zero;
void Update () {
    if (WaveVR_Controller.Input (WaveVR_Controller.EDeviceType.Dominant).GetPressDown (wvr.WVR_InputId.WVR_InputId_Alias1_Touchpad))
    {
        targetLocation = WaveVR_RaycastResultProvider.Instance.GetRaycastResult (WaveVR_Controller.EDeviceType.Dominant).worldPosition;
    }
}
  1. Then, write the teleport function OnTeleport :
private void OnTeleport(Vector3 position)
{
    // Get the head's local position.
    Vector3 head_position = head.transform.localPosition;

    // Calculate the final teleport position.
    Vector3 teleport_position = Vector3.zero;
    teleport_position.x = position.x - head_position.x;
    teleport_position.y = position.y + transform.localPosition.y;    // Remember to add the body height.
    teleport_position.z = position.z - head_position.z;

    // Go teleport!
    transform.localPosition = teleport_position;
}
  1. Finally, if you want to teleport when the Dominant Touchpad key is pressed, please call the OnTeleport function inside the if case of the Update function:
void Update () {
    if (WaveVR_Controller.Input (WaveVR_Controller.EDeviceType.Dominant).GetPressDown (wvr.WVR_InputId.WVR_InputId_Alias1_Touchpad))
    {
        targetLocation = WaveVR_RaycastResultProvider.Instance.GetRaycastResult (WaveVR_Controller.EDeviceType.Dominant).worldPosition;
        OnTeleport (targetLocation);
    }
}

Other Reference

If you are interested in more information about the Teleport feature, please refer to the sample Teleport_Test which is located in Assets/Samples/Teleport_Test.

The sample demonstrates another method of the Teleport. So there is not only one method to implement the Teleport feature and the main idea is to change the location of WaveVR’s parent object.