Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SteamVR Teleport Area doesn't work after changing Player Transform.

Discussion in 'VR' started by cakefile, Aug 1, 2019.

  1. cakefile

    cakefile

    Joined:
    Dec 12, 2018
    Posts:
    3
    I have two teleport areas. The player is supposed to click a button in one room (with its own teleport area) in order to be teleported into another room with a second teleport area. But when he is teleported, the area doesn't work. The area and the arc that indicates the target location are still shown, but after the button is released the player stays in position. Before I implemented the change of player transform, both areas worked fine. So I think that the error lies in there.

    Here is the code that changes the player's Transform:

    Code (CSharp):
    1.  
    2. public class TeleportRoomController : MonoBehaviour
    3. {
    4.     public GameObject cube;
    5.     public GameObject target;
    6.     public GameObject startTrigger;
    7.     public SteamVR_Action_Boolean triggerClick;
    8.     public GameObject rightHand;
    9.     public GameObject player;
    10.     public Transform mainPlayerPosition;
    11.    
    12.     private bool start = false;
    13.     private float x;
    14.     private float y;
    15.     private float z;
    16.     private const SteamVR_Input_Sources hand = SteamVR_Input_Sources.Any;
    17.  
    18.     void Update()
    19.     {
    20. // translate the player if the button was pressed
    21.         if (start)
    22.         {
    23.             cube.SetActive(false);
    24.             player.transform.position = mainPlayerPosition.position;
    25.             player.transform.rotation = mainPlayerPosition.rotation;
    26.             target.SetActive(true);
    27.         }
    28.     }
    29.  
    30.     private void OnEnable()
    31.     {
    32.         triggerClick.AddOnStateDownListener(translateCube, hand);
    33.     }
    34.  
    35.     private void OnDisable()
    36.     {
    37.         triggerClick.RemoveOnStateDownListener(translateCube, hand);
    38.     }
    39.  
    40. // if the button was pressed, start is changed to "true"
    41.     void translateCube(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
    42.     {
    43.         switch (fromSource)
    44.         {
    45.             case SteamVR_Input_Sources.Any:
    46.                 float buttonDistance = Vector3.Distance(rightHand.transform.position, startTrigger.transform.position);
    47.  
    48.                 if (buttonDistance <= 0.4)
    49.                 {
    50.                     start = true;
    51.                 }
    52.                
    53.                 break;
    54.             // more cases
    55.         }
    56.     }
    57. }
    58.  
    The boolean "start" should indicate whether the button was pressed.

    I've already tried
    1. Using one large teleport area instead of two.
    2. Translating the teleport area along with the player

    Is there another way to change the player's position within one scene, so that the teleport areas can still work?
    BTW I use a Vive Pro in case that matters.