Hello, I have a unity project using OpenVR using the HTC Vive Focus 3 using the XR Action Based Movement system. I am trying to make it to where when the user clicks the joysticks it activates the teleport ray and teleports when the joystick is let go. Right now the ray i have both interacts with UI and teleports, but i want them to be seperated.
![image|690x372]. I tried to create a new input but i couldn’t find what bindings to use for the teleport. I have attached my bindings for my rays.
Hey @curbybair. Have you looked at the XR Origin (XR Rig) prefab in the XRI Starter Assets Sample package? It looks like you might be using the Input Actions to some extent, but in the prefab we set up a similar mechanism using the Controller Input Action Manager script to toggle between grab ray and teleport ray. The main changes you would have to make would be the input action binding that activates teleport (XRI Left Locomotion/Teleport Mode).
1 Like
I am using Unity 2019.4, so i’m using an older version of the XR Interaction Toolkit (2.1.1) and don’t seem to have the example you provided.
Just wanted to post the solution I used if it would be help to anyone. This requires some objects but more than likely you should have these.
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR.Interaction.Toolkit;
public class ActivateTeleportationRay : MonoBehaviour
{
public GameObject leftTeleportRay;
public GameObject rightTeleportRay;
public InputActionProperty leftStick;
public InputActionProperty rightStick;
public TeleportationProvider teleportationProvider;
private bool leftStickWasActive = false;
private bool rightStickWasActive = false;
// Add references to the XR Ray Interactors
public XRRayInteractor leftRayInteractor;
public XRRayInteractor rightRayInteractor;
void Update()
{
Vector2 leftStickValue = leftStick.action.ReadValue<Vector2>();
Vector2 rightStickValue = rightStick.action.ReadValue<Vector2>();
// Check if left stick is moved
if (leftStickValue.magnitude > 0.1f)
{
leftTeleportRay.SetActive(true);
leftStickWasActive = true;
}
// Trigger teleport on left stick release
else if (leftStickWasActive)
{
leftStickWasActive = false;
leftTeleportRay.SetActive(false);
// Trigger teleport through XR Ray Interactor when stick is released
TriggerTeleport(leftRayInteractor);
}
// Check if right stick is moved
if (rightStickValue.magnitude > 0.1f)
{
rightTeleportRay.SetActive(true);
rightStickWasActive = true;
}
// Trigger teleport on right stick release
else if (rightStickWasActive)
{
rightStickWasActive = false;
rightTeleportRay.SetActive(false);
// Trigger teleport through XR Ray Interactor when stick is released
TriggerTeleport(rightRayInteractor);
}
}
private void TriggerTeleport(XRRayInteractor rayInteractor)
{
if (teleportationProvider != null && rayInteractor != null && rayInteractor.enabled)
{
// Trigger the interaction as if a teleportation button was pressed
rayInteractor.TryGetCurrent3DRaycastHit(out RaycastHit hit);
if (hit.collider != null)
{
TeleportRequest request = new TeleportRequest()
{
destinationPosition = hit.point,
matchOrientation = MatchOrientation.None
};
// Queue the teleport request
teleportationProvider.QueueTeleportRequest(request);
}
}
else
{
Debug.LogWarning("Teleportation provider or ray interactor is not available.");
}
}
}


