diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index 1c2bc7e..bd5c507 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -1,5 +1,4 @@ using ABI_RC.Core.Player; -using ABI_RC.Core.Savior; using ABI_RC.Systems.IK; using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.MovementSystem; @@ -49,6 +48,8 @@ namespace ml_amt Vector3 m_massCenter = Vector3.zero; + Transform m_ikLimits = null; + readonly List m_parameters = null; internal MotionTweaker() @@ -92,6 +93,8 @@ namespace ml_amt m_groundedRaw = MovementSystem.Instance.IsGroundedRaw(); m_moving = !Mathf.Approximately(MovementSystem.Instance.movementVector.magnitude, 0f); + UpdateIKLimits(); + if(m_avatarHips != null) { Vector4 l_hipsToPoint = (PlayerSetup.Instance.transform.GetMatrix().inverse * m_avatarHips.GetMatrix()) * ms_pointVector; @@ -129,6 +132,7 @@ namespace ml_amt m_hipsToPlayer = Vector3.zero; m_avatarHips = null; m_massCenter = Vector3.zero; + m_ikLimits = null; m_parameters.Clear(); } @@ -146,6 +150,10 @@ namespace ml_amt m_parameters.Add(new AvatarParameter(AvatarParameter.ParameterType.Moving, PlayerSetup.Instance.animatorManager)); m_parameters.RemoveAll(p => !p.IsValid()); + // Avatar custom IK limits + m_ikLimits = PlayerSetup.Instance._avatar.transform.Find("[IKLimits]"); + UpdateIKLimits(); + // Apply VRIK tweaks if(m_vrIk != null) { @@ -276,11 +284,13 @@ namespace ml_amt // Settings internal void SetCrouchLimit(float p_value) { - PlayerSetup.Instance.avatarCrouchLimit = Mathf.Max(Mathf.Clamp01(p_value), PlayerSetup.Instance.avatarProneLimit); + if(m_ikLimits == null) + PlayerSetup.Instance.avatarCrouchLimit = Mathf.Max(Mathf.Clamp01(p_value), PlayerSetup.Instance.avatarProneLimit); } internal void SetProneLimit(float p_value) { - PlayerSetup.Instance.avatarProneLimit = Mathf.Min(Mathf.Clamp01(p_value), PlayerSetup.Instance.avatarCrouchLimit); + if(m_ikLimits == null) + PlayerSetup.Instance.avatarProneLimit = Mathf.Min(Mathf.Clamp01(p_value), PlayerSetup.Instance.avatarCrouchLimit); } internal void SetIKOverrideFly(bool p_state) { @@ -310,6 +320,16 @@ namespace ml_amt return ((m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f); } + void UpdateIKLimits() + { + if(m_ikLimits != null) + { + Vector3 l_values = m_ikLimits.localPosition; + PlayerSetup.Instance.avatarCrouchLimit = Mathf.Max(Mathf.Clamp01(l_values.x), Mathf.Clamp01(l_values.y)); + PlayerSetup.Instance.avatarProneLimit = Mathf.Min(Mathf.Clamp01(l_values.x), Mathf.Clamp01(l_values.y)); + } + } + // Parameters access public float GetUpright() => PlayerSetup.Instance.avatarUpright; public bool GetGroundedRaw() => m_groundedRaw; diff --git a/ml_amt/Properties/AssemblyInfo.cs b/ml_amt/Properties/AssemblyInfo.cs index e4e35a9..a4e1f79 100644 --- a/ml_amt/Properties/AssemblyInfo.cs +++ b/ml_amt/Properties/AssemblyInfo.cs @@ -1,6 +1,4 @@ -using System.Reflection; - -[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.9", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.9", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonOptionalDependencies("ml_prm", "ml_pmc")] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] diff --git a/ml_amt/README.md b/ml_amt/README.md index 7732bdf..5ea9c4a 100644 --- a/ml_amt/README.md +++ b/ml_amt/README.md @@ -37,4 +37,5 @@ Available additional parameters for AAS animator: * Note: Can be set as local-only (not synced) if starts with `#` character. Additional mod's behaviour: -* Overrides and fixes IK behaviour in 4PT mode (head, hands and hips). \ No newline at end of file +* Overrides and fixes IK behaviour in 4PT mode (head, hands and hips). +* Avatars can have controlled IK crouch and prone limits. For that create `[IKLimits]` GameObject parented to avatar's root. Its local X and Y positions will be used as crouch and prone limits respectively and can be changed via animations. Values should be in range of [0;1]. \ No newline at end of file