Hi I just posted a very similar question then saw this post. Iād be fearful of updating the XR integration toolkit in case it breaks existing builds. Love to hear any feedback if they have tried this yet?. Cheers
It took me a bit to find the correct class within the XR Toolkit, but if you are using the Unity XR Toolkit, you can create a teleportation request then pass it into the QueueTeleportRequest() class on the TeleportationProvider.cs. To accomplish this, you can make a class like this:
using UnityEngine.XR.Interaction.Toolkit;
...
public TeleportationProvider teleporter;
public GameObject targObj;
public void ForceTeleport(){
TeleportRequest teleportRequest = new TeleportRequest();
teleportRequest.destinationPosition = targObj.transform.position;
teleportRequest.destinationRotation = targObj.transform.rotation;
teleportRequest.matchOrientation = MatchOrientation.TargetUpAndForward;
teleporter.QueueTeleportRequest(teleportRequest);
}
This class can be called to force the user to teleport to the targObj position and rotation. you can find more info on teleport requests here: Struct TeleportRequest
Thanks yes I discovered a similar approach, this compensates for the direction the player is currently looking towards.
/// <summary>
/// // =========== TELEPORT TO LOCATION ===========
/// </summary>
public void teleportToLocation(GameObject thisLlocation)
{
sceneFADER.SetActive(true); // Allow screen fade before Teleport
sceneFADER.GetComponent<FadeScreen>().FadeOut(.05f);
StartCoroutine(DoTeleportToLocation(thisLlocation));
}
private IEnumerator DoTeleportToLocation(GameObject targetTeleportLocation)
{
yield return new WaitForSeconds(.3f); // needs a small delay for positioning to work when scene initially loads
// Get the target rotation
Quaternion targetRotation = targetTeleportLocation.transform.rotation;
// Create a TeleportRequest with the target position and rotation
TeleportRequest teleportRequest = new TeleportRequest()
{
destinationPosition = targetTeleportLocation.transform.position,
destinationRotation = targetRotation
};
// Queue teleportation request
teleportationProvider.QueueTeleportRequest(teleportRequest);
// Get the current camera rotation
Quaternion cameraRotation = Quaternion.Euler(0f, MainCamera.transform.localEulerAngles.y, 0f);
// Rotate the XR Rig's XROrigin to face the correct direction after teleportation, considering camera rotation
PlayerXR_Origin.transform.rotation = targetRotation * Quaternion.Inverse(cameraRotation);
yield return new WaitForSeconds(.2f);
sceneFADER.GetComponent<FadeScreen>().FadeIn(.05f);
yield return new WaitForSeconds(.1f);
sceneFADER.SetActive(false);
}