mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-03 14:59:23 +00:00
[PlaySpaceScaleFix] Add comments cause I forget ez
This commit is contained in:
parent
829b858e56
commit
0d673e5bbc
1 changed files with 17 additions and 3 deletions
|
@ -7,6 +7,16 @@ namespace NAK.PlaySpaceScaleFix.HarmonyPatches;
|
||||||
|
|
||||||
class PlayerSetupPatches
|
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]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))]
|
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))]
|
||||||
static void Prefix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance, ref Vector3 __state)
|
static void Prefix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance, ref Vector3 __state)
|
||||||
|
@ -19,9 +29,11 @@ class PlayerSetupPatches
|
||||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))]
|
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))]
|
||||||
static void Postfix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance, ref Vector3 __state)
|
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)
|
if (!PlaySpaceScaleFix.EntryEnabled.Value || !MetaPort.Instance.isUsingVr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Vector3 newPosition = __instance.vrCamera.transform.position;
|
Vector3 newPosition = __instance.vrCamera.transform.position;
|
||||||
newPosition.y = __instance.transform.position.y;
|
newPosition.y = __instance.transform.position.y;
|
||||||
|
|
||||||
|
@ -33,8 +45,10 @@ class PlayerSetupPatches
|
||||||
// Scale avatar local position to keep avatar in place
|
// Scale avatar local position to keep avatar in place
|
||||||
if (__instance._avatar != null)
|
if (__instance._avatar != null)
|
||||||
{
|
{
|
||||||
Vector3 scaleDifference = __instance.DivideVectors(__instance._avatar.transform.localScale, __instance.lastScale);
|
// This calculation done in PlayerSetup.CheckUpdateAvatarScaleToPlaySpaceRelation already, but using Initial scale.
|
||||||
__instance._avatar.transform.localPosition = Vector3.Scale(__instance._avatar.transform.localPosition, scaleDifference);
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue