From b519a8ee5ab10b14f772a42fcc5572b0acc01cfe Mon Sep 17 00:00:00 2001 From: SDraw Date: Wed, 30 Oct 2024 18:42:47 +0300 Subject: [PATCH] Fix of lagging player position when ragdolled --- README.md | 2 +- ml_prm/Properties/AssemblyInfo.cs | 2 +- ml_prm/RagdollController.cs | 54 ++++++++++++++++--------------- ml_prm/ml_prm.csproj | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 9d07ae6..76ae5bd 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,6 @@ Merged set of MelonLoader mods for ChilloutVR. |[Leap Motion Extension](/ml_lme/README.md)| 1.6.0 [:arrow_down:](../../releases/latest/download/LeapMotionExtension.dll)| |[Pickup Arm Movement](/ml_pam/README.md)|1.2.0 [:arrow_down:](../../releases/latest/download/PickupArmMovement.dll)| |[Player Movement Copycat](/ml_pmc/README.md)|1.1.0 [:arrow_down:](../../releases/latest/download/PlayerMovementCopycat.dll)| -|[Player Ragdoll Mod](/ml_prm/README.md)|1.2.0 [:arrow_down:](../../releases/latest/download/PlayerRagdollMod.dll)| +|[Player Ragdoll Mod](/ml_prm/README.md)|1.2.1 [:arrow_down:](../../releases/latest/download/PlayerRagdollMod.dll)| |[Players Instance Notifier](/ml_pin/README.md)|1.1.0 [:arrow_down:](../../releases/latest/download/PlayersInstanceNotifier.dll)| |[Vive Extended Input](/ml_vei/README.md)|1.1.0 [:arrow_down:](../../releases/latest/download/ViveExtendedInput.dll)| diff --git a/ml_prm/Properties/AssemblyInfo.cs b/ml_prm/Properties/AssemblyInfo.cs index 6284cdc..6a92fe5 100644 --- a/ml_prm/Properties/AssemblyInfo.cs +++ b/ml_prm/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.2.0", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.2.1", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonPriority(2)] [assembly: MelonLoader.MelonAdditionalDependencies("BTKUILib")] diff --git a/ml_prm/RagdollController.cs b/ml_prm/RagdollController.cs index 61cf9f3..6a69c8f 100644 --- a/ml_prm/RagdollController.cs +++ b/ml_prm/RagdollController.cs @@ -225,30 +225,14 @@ void Update() } } - void FixedUpdate() - { - if(m_avatarReady && m_ragdolled) - { - Vector3 l_diff = m_puppetReferences.hips.position - m_lastRagdollPosition; - m_playerPlane.SetNormalAndPosition(PlayerSetup.Instance.transform.rotation * Vector3.up, PlayerSetup.Instance.transform.position); - - PlayerSetup.Instance.transform.position += l_diff; - m_lastRagdollPosition = m_puppetReferences.hips.position; - - // Project on plane and fix our position if we under previous plane - if(m_playerPlane.GetDistanceToPoint(m_lastRagdollPosition) < 0f) - m_playerPlane.Flip(); - if(m_playerPlane.GetDistanceToPoint(PlayerSetup.Instance.transform.position) < 0f) - PlayerSetup.Instance.transform.position = m_playerPlane.ClosestPointOnPlane(PlayerSetup.Instance.transform.position); - } - } - void LateUpdate() { if(m_avatarReady) { if(m_ragdolled) { + MovePlayer(); + foreach(var l_link in m_boneLinks) l_link.Item1.CopyGlobal(l_link.Item2); } @@ -748,14 +732,6 @@ public void Unragdoll() } } - static Transform CloneTransform(Transform p_source, Transform p_parent, string p_name) - { - Transform l_target = new GameObject(p_name).transform; - l_target.parent = p_parent; - p_source.CopyGlobal(l_target); - return l_target; - } - bool CanRagdoll() { if(WorldManager.IsRestrictedWorld()) @@ -774,6 +750,23 @@ bool CanUnragdoll() return (l_result || m_forcedSwitch); } + void MovePlayer() + { + // Pain + Vector3 l_up = PlayerSetup.Instance.transform.rotation * Vector3.up; + Vector3 l_diff = m_puppetReferences.hips.position - m_lastRagdollPosition; + m_playerPlane.SetNormalAndPosition(l_up, PlayerSetup.Instance.transform.position); + + PlayerSetup.Instance.transform.position += l_diff; + m_lastRagdollPosition = m_puppetReferences.hips.position; + + // Try to tether player position closer to hips rigid body position + if(m_playerPlane.GetDistanceToPoint(m_lastRagdollPosition) < 0f) + m_playerPlane.SetNormalAndPosition(l_up, m_lastRagdollPosition); + if(m_playerPlane.GetDistanceToPoint(PlayerSetup.Instance.transform.position) < 0f) + PlayerSetup.Instance.transform.position = m_playerPlane.ClosestPointOnPlane(PlayerSetup.Instance.transform.position); + } + static void TryRestoreMovement() { bool l_state = true; @@ -783,5 +776,14 @@ static void TryRestoreMovement() if(l_state) BetterBetterCharacterController.Instance.SetImmobilized(false); } + + + static Transform CloneTransform(Transform p_source, Transform p_parent, string p_name) + { + Transform l_target = new GameObject(p_name).transform; + l_target.parent = p_parent; + p_source.CopyGlobal(l_target); + return l_target; + } } } diff --git a/ml_prm/ml_prm.csproj b/ml_prm/ml_prm.csproj index 8b52c74..065b449 100644 --- a/ml_prm/ml_prm.csproj +++ b/ml_prm/ml_prm.csproj @@ -4,7 +4,7 @@ netstandard2.1 x64 PlayerRagdollMod - 1.2.0 + 1.2.1 SDraw SDraw PlayerRagdollMod