vrchat-community / ClientSim

Client Simulator for World Building
https://clientsim.docs.vrchat.com
Other
239 stars 25 forks source link

[3.6.1] VRCPlayerApi.TeleportTo with AlignRoomWithSpawnPoint does not teleport the player to the correct location. #118

Open CyanLaser opened 5 months ago

CyanLaser commented 5 months ago

Using VRCPlayerApi.TeleportTo with AlignRoomWithSpawnPoint results in broken teleportation behavior. This has been broken since ClientSim's initial release.

Looking at the code, the handling of "from playspace" is basically the same code from CyanEmu, not properly considering how the PlayerController's hierarchy has changed.

https://github.com/vrchat-community/ClientSim/blob/43e43b046fa2aff9b31d64698fc0868df43b44eb/Packages/com.vrchat.ClientSim/Runtime/Player/ClientSimPlayerController.cs#L230-L235

https://github.com/CyanLaser/CyanEmu/blob/daf42066ab61e73c187cc6f16352304735c28343/CyanEmu/Scripts/CyanEmuPlayerController.cs#L519-L523

Here is a potential fix:

if (fromPlaySpace)
{
    var playspaceData = _trackingProvider.GetTrackingData(VRCPlayerApi.TrackingDataType.Origin);
    Vector3 playspacePos = playspaceData.position - transform.position;
    Quaternion playspaceRot = playspaceData.rotation * Quaternion.Inverse(transform.rotation);
    floorRotation = Quaternion.Inverse(playspaceRot) * floorRotation;
    position = position + floorRotation * -playspacePos;
}

I'm disappointed that no one has reported or fixed this bug in the past 3 years, even though I know many creators have referenced it...

TapGhoul commented 4 months ago

Related - it seems TrackingDataType.AvatarRoot always returns (0, 0, 0), and has been broken for the same duration as this has - both of these bugs exit as far back as 3.5.1, maybe earlier.