Last active
September 6, 2023 17:28
-
-
Save hai-vr/8bfa8f2cbb73d211e790dc75045c96a4 to your computer and use it in GitHub Desktop.
StableTeleportTo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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