[PlaySpaceScaleFix] Add comments cause I forget ez

This commit is contained in:
NotAKidoS 2023-06-24 14:10:12 -05:00
parent 829b858e56
commit 0d673e5bbc

View file

@ -7,6 +7,16 @@ namespace NAK.PlaySpaceScaleFix.HarmonyPatches;
class PlayerSetupPatches
{
/**
Store vrCamera position before vrRig is scaled.
Use new vrCamera position after vrRig is scaled to get an offset.
Use offset on _PlayerLocal object to keep player in place.
Calculate scale difference, use to scale the avatars local position to keep avatar in place.
**/
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))]
static void Prefix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance, ref Vector3 __state)
@ -19,6 +29,8 @@ class PlayerSetupPatches
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))]
static void Postfix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance, ref Vector3 __state)
{
// DesktopVRSwitch might allow an offset other than 0,0,0 for the vrCamera in Desktop
// Safest to just not run this patch if in Desktop, as Desktop doesn't have an offset at all anyways
if (!PlaySpaceScaleFix.EntryEnabled.Value || !MetaPort.Instance.isUsingVr)
return;
@ -33,8 +45,10 @@ class PlayerSetupPatches
// Scale avatar local position to keep avatar in place
if (__instance._avatar != null)
{
Vector3 scaleDifference = __instance.DivideVectors(__instance._avatar.transform.localScale, __instance.lastScale);
__instance._avatar.transform.localPosition = Vector3.Scale(__instance._avatar.transform.localPosition, scaleDifference);
// This calculation done in PlayerSetup.CheckUpdateAvatarScaleToPlaySpaceRelation already, but using Initial scale.
// We only need difference between last and current scale for scaling the localposition.
Vector3 scaleDifferenceNotInitial = __instance.DivideVectors(__instance._avatar.transform.localScale, __instance.lastScale);
__instance._avatar.transform.localPosition = Vector3.Scale(__instance._avatar.transform.localPosition, scaleDifferenceNotInitial);
}
}
}