Scaled locomotion steps

Funny C# properties
Minor fixes
This commit is contained in:
SDraw 2023-03-03 00:44:17 +03:00
parent fc60219a4e
commit 28aca1bb49
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
11 changed files with 343 additions and 410 deletions

View file

@ -1,4 +1,5 @@
using ABI_RC.Core.Player;
using ABI_RC.Systems.IK;
using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Systems.MovementSystem;
using RootMotion.FinalIK;
@ -65,6 +66,7 @@ namespace ml_amt
bool m_followHips = true;
Vector3 m_hipsToPlayer = Vector3.zero;
Vector2 m_stepDistance = Vector2.zero;
Vector3 m_massCenter = Vector3.zero;
readonly List<AvatarParameter> m_parameters = null;
@ -74,6 +76,7 @@ namespace ml_amt
m_parameters = new List<AvatarParameter>();
}
// Unity events
void Start()
{
m_inVR = Utils.IsInVR();
@ -88,7 +91,8 @@ namespace ml_amt
Settings.IKOverrideJumpChange += this.SetIKOverrideJump;
Settings.DetectEmotesChange += this.SetDetectEmotes;
Settings.FollowHipsChange += this.SetFollowHips;
Settings.MassCenterChange += this.SetMassCenter;
Settings.MassCenterChange += this.OnMassCenterChange;
Settings.ScaledStepsChange += this.OnScaledStepsChange;
}
void OnDestroy()
@ -103,7 +107,7 @@ namespace ml_amt
Settings.IKOverrideJumpChange -= this.SetIKOverrideJump;
Settings.DetectEmotesChange -= this.SetDetectEmotes;
Settings.FollowHipsChange -= this.SetFollowHips;
Settings.MassCenterChange -= this.SetMassCenter;
Settings.MassCenterChange -= this.OnMassCenterChange;
}
void Update()
@ -163,6 +167,7 @@ namespace ml_amt
}
}
// Game events
internal void OnAvatarClear()
{
m_vrIk = null;
@ -183,6 +188,7 @@ namespace ml_amt
m_avatarHips = null;
m_viewPointHeight = 1f;
m_massCenter = Vector3.zero;
m_stepDistance = Vector2.zero;
m_parameters.Clear();
}
@ -253,6 +259,8 @@ namespace ml_amt
m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? m_massCenter : m_locomotionOffset);
m_stepDistance.Set(m_vrIk.solver.locomotion.stepThreshold, m_vrIk.solver.locomotion.footDistance);
m_vrIk.onPreSolverUpdate.AddListener(this.OnIKPreUpdate);
m_vrIk.onPostSolverUpdate.AddListener(this.OnIKPostUpdate);
}
@ -276,12 +284,23 @@ namespace ml_amt
internal void OnPlayspaceScale()
{
if((m_vrIk != null) && Settings.MassCenter)
if(m_vrIk != null)
{
m_vrIk.solver.locomotion.offset = m_massCenter * GetRelativeScale();
if(Settings.MassCenter)
m_vrIk.solver.locomotion.offset = m_massCenter * GetRelativeScale();
if(Settings.ScaledSteps)
{
m_vrIk.solver.locomotion.stepThreshold = m_stepDistance.x * GetRelativeScale();
m_vrIk.solver.locomotion.footDistance = m_stepDistance.y * GetRelativeScale();
m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f);
m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f);
}
}
}
// IK events
void OnIKPreUpdate()
{
bool l_locomotionOverride = false;
@ -342,25 +361,26 @@ namespace ml_amt
m_vrIk.solver.rightLeg.useAnimatedBendNormal = m_bendNormalRight;
}
public void SetIKOverrideCrouch(bool p_state)
// Settings
internal void SetIKOverrideCrouch(bool p_state)
{
m_ikOverrideCrouch = p_state;
}
public void SetCrouchLimit(float p_value)
internal void SetCrouchLimit(float p_value)
{
if(!m_customCrouchLimit)
m_crouchLimit = Mathf.Clamp01(p_value);
}
public void SetIKOverrideProne(bool p_state)
internal void SetIKOverrideProne(bool p_state)
{
m_ikOverrideProne = p_state;
}
public void SetProneLimit(float p_value)
internal void SetProneLimit(float p_value)
{
if(!m_customProneLimit)
m_proneLimit = Mathf.Clamp01(p_value);
}
public void SetPoseTransitions(bool p_state)
internal void SetPoseTransitions(bool p_state)
{
m_poseTransitions = p_state;
@ -370,7 +390,7 @@ namespace ml_amt
PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool("Prone", false);
}
}
public void SetAdjustedMovement(bool p_state)
internal void SetAdjustedMovement(bool p_state)
{
m_adjustedMovement = p_state;
@ -380,33 +400,54 @@ namespace ml_amt
MovementSystem.Instance.ChangeProne(false);
}
}
public void SetIKOverrideFly(bool p_state)
internal void SetIKOverrideFly(bool p_state)
{
m_ikOverrideFly = p_state;
}
public void SetIKOverrideJump(bool p_state)
internal void SetIKOverrideJump(bool p_state)
{
m_ikOverrideJump = p_state;
}
public void SetDetectEmotes(bool p_state)
internal void SetDetectEmotes(bool p_state)
{
m_detectEmotes = p_state;
}
public void SetFollowHips(bool p_state)
internal void SetFollowHips(bool p_state)
{
m_followHips = p_state;
}
public void SetMassCenter(bool p_state)
void OnMassCenterChange(bool p_state)
{
if(m_vrIk != null)
m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? (m_massCenter * GetRelativeScale()) : m_locomotionOffset);
}
void OnScaledStepsChange(bool p_state)
{
if(m_vrIk != null)
{
if(p_state)
{
m_vrIk.solver.locomotion.stepThreshold = m_stepDistance.x * GetRelativeScale();
m_vrIk.solver.locomotion.footDistance = m_stepDistance.y * GetRelativeScale();
m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f);
m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f);
}
else
{
IKSystem.Instance.ApplyAvatarScaleToIk(PlayerSetup.Instance.GetAvatarHeight());
m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(0.03f);
m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(0.03f);
}
}
}
// Arbitrary
float GetRelativeScale()
{
return ((m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f);
}
// Parameters access
public float GetUpright() => m_upright;
public bool GetGroundedRaw() => m_groundedRaw;
public bool GetMoving() => m_moving;