Skip to content

Commit

Permalink
Fix of lagging player position when ragdolled
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Oct 30, 2024
1 parent df46abb commit b519a8e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)|
2 changes: 1 addition & 1 deletion ml_prm/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
54 changes: 28 additions & 26 deletions ml_prm/RagdollController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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())
Expand All @@ -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;
Expand All @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion ml_prm/ml_prm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Platforms>x64</Platforms>
<PackageId>PlayerRagdollMod</PackageId>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<Authors>SDraw</Authors>
<Company>SDraw</Company>
<Product>PlayerRagdollMod</Product>
Expand Down

0 comments on commit b519a8e

Please sign in to comment.