Skip to content

Instantly share code, notes, and snippets.

@hai-vr
Last active September 6, 2023 17:28
Show Gist options
  • Save hai-vr/8bfa8f2cbb73d211e790dc75045c96a4 to your computer and use it in GitHub Desktop.
Save hai-vr/8bfa8f2cbb73d211e790dc75045c96a4 to your computer and use it in GitHub Desktop.
StableTeleportTo.cs
/*
This code snippet is released into the public domain.
If the public domain is not applicable where you are, then it's released under the terms of the CC0 1.0 Universal, which is essentially the same as public domain.
*/
// Teleport to self
StableTeleportTo(Networking.LocalPlayer.GetPosition());
// Teleport to other position
public Vector3 destinationPos = ...;
StableTeleportTo(destinationPos);
private static void StableTeleportTo(Vector3 destinationPos)
{
var playerPos = Networking.LocalPlayer.GetPosition();
var playerOrigin = Networking.LocalPlayer.GetTrackingData(VRCPlayerApi.TrackingDataType.Origin);
var posToOrigin = playerOrigin.position - playerPos;
var destinationOrigin = destinationPos + posToOrigin;
Networking.LocalPlayer.TeleportTo(
destinationOrigin,
playerOrigin.rotation,
VRC_SceneDescriptor.SpawnOrientation.AlignRoomWithSpawnPoint
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment