Custom IK limits

This commit is contained in:
SDraw 2023-07-28 11:04:50 +03:00
parent 19032650a3
commit de2cd0fd56
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
3 changed files with 26 additions and 7 deletions

View file

@ -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<AvatarParameter> 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,10 +284,12 @@ namespace ml_amt
// Settings
internal void SetCrouchLimit(float p_value)
{
if(m_ikLimits == null)
PlayerSetup.Instance.avatarCrouchLimit = Mathf.Max(Mathf.Clamp01(p_value), PlayerSetup.Instance.avatarProneLimit);
}
internal void SetProneLimit(float p_value)
{
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;

View file

@ -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)]

View file

@ -38,3 +38,4 @@ Available additional parameters for AAS animator:
Additional mod's behaviour:
* 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].