Transformation fixes

More checks for non-flying worlds
This commit is contained in:
SDraw 2023-05-28 16:47:04 +03:00
parent 9159946de6
commit 732b15a6a9
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
9 changed files with 43 additions and 35 deletions

View file

@ -130,10 +130,10 @@ namespace ml_prm
{
try
{
if (m_localController != null)
if(m_localController != null)
m_localController.OnAvatarScaling(1f + p_scaleDifference);
}
catch (Exception e)
catch(Exception e)
{
MelonLoader.MelonLogger.Error(e);
}

View file

@ -1,10 +1,10 @@
using System.Reflection;
[assembly: AssemblyTitle("PlayerRagdollMod")]
[assembly: AssemblyVersion("1.0.4")]
[assembly: AssemblyFileVersion("1.0.4")]
[assembly: AssemblyVersion("1.0.5")]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.0.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.0.5", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
[assembly: MelonLoader.MelonPriority(2)]
[assembly: MelonLoader.MelonOptionalDependencies("BTKUILib")]

View file

@ -41,6 +41,7 @@ namespace ml_prm
readonly PhysicMaterial m_physicsMaterial = null;
bool m_reachedGround = true;
float m_groundedTime = 0f;
float m_downTime = float.MinValue;
internal RagdollController()
@ -115,10 +116,14 @@ namespace ml_prm
Vector3 l_pos = PlayerSetup.Instance.transform.position;
m_velocity = (m_velocity + (l_pos - m_lastPosition) / Time.deltaTime) * 0.5f;
m_lastPosition = l_pos;
}
if(m_avatarReady && !m_reachedGround)
m_reachedGround = MovementSystem.Instance.IsGrounded();
if(!m_reachedGround && MovementSystem.Instance.IsGrounded())
{
m_groundedTime += Time.deltaTime;
if(m_groundedTime >= 0.25f)
m_reachedGround = true;
}
}
if(m_avatarReady && m_enabled && !BodySystem.isCalibrating)
BodySystem.TrackingPositionWeight = 0f;
@ -189,6 +194,7 @@ namespace ml_prm
m_boneLinks.Clear();
m_jointAnchors.Clear();
m_reachedGround = true;
m_groundedTime = 0f;
m_downTime = float.MinValue;
m_puppetRoot.localScale = Vector3.one;
}
@ -335,7 +341,10 @@ namespace ml_prm
internal void OnCombatDown()
{
if(m_avatarReady && !m_enabled && Settings.CombatReaction)
{
m_reachedGround = true;
SwitchRagdoll();
}
}
internal void OnToggleFlight()
@ -451,7 +460,10 @@ namespace ml_prm
BodySystem.TrackingPositionWeight = 0f;
if(!Utils.IsWorldSafe())
{
m_reachedGround = false; // Force player to unragdoll and reach ground first
m_groundedTime = 0f;
}
m_puppetRoot.gameObject.SetActive(true);
@ -485,6 +497,13 @@ namespace ml_prm
if(IsSafeToUnragdoll())
{
MovementSystem.Instance.SetImmobilized(false);
if(!Utils.IsWorldSafe())
{
Vector3 l_vec = MovementSystem.Instance.GetAppliedGravity();
l_vec.y = Mathf.Clamp(l_vec.y, float.MinValue, 0f);
MovementSystem.Instance.SetAppliedGravity(l_vec);
}
m_ragdolledParameter.SetValue(false);
if(!BodySystem.isCalibrating)
BodySystem.TrackingPositionWeight = 1f;

View file

@ -8,7 +8,8 @@ namespace ml_prm
{
static class Utils
{
static readonly FieldInfo ms_grounded = typeof(MovementSystem).GetField("_isGrounded", BindingFlags.NonPublic | BindingFlags.Instance);
static readonly FieldInfo ms_groundedRaw = typeof(MovementSystem).GetField("_isGroundedRaw", BindingFlags.NonPublic | BindingFlags.Instance);
static readonly FieldInfo ms_appliedGravity = typeof(MovementSystem).GetField("_appliedGravity", BindingFlags.NonPublic | BindingFlags.Instance);
public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded);
public static bool IsWorldSafe() => ((CVRWorld.Instance != null) && CVRWorld.Instance.allowFlying);
@ -25,7 +26,9 @@ namespace ml_prm
return l_result;
}
public static bool IsGrounded(this MovementSystem p_instance) => (bool)ms_grounded.GetValue(p_instance);
public static bool IsGrounded(this MovementSystem p_instance) => (bool)ms_groundedRaw.GetValue(p_instance);
public static Vector3 GetAppliedGravity(this MovementSystem p_instance) => (Vector3)ms_appliedGravity.GetValue(p_instance);
public static void SetAppliedGravity(this MovementSystem p_instance, Vector3 p_vec) => ms_appliedGravity.SetValue(p_instance, p_vec);
public static void CopyGlobal(this Transform p_source, Transform p_target)
{