Skip to content

Commit

Permalink
IK reset after locomotion override
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Feb 25, 2023
1 parent 98af853 commit 3940802
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ml_amt/MotionTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum PoseState
bool m_grounded = false;
bool m_groundedRaw = false;
bool m_moving = false;
bool m_locomotionOverride = false;

bool m_ikOverrideCrouch = true;
float m_crouchLimit = 0.65f;
Expand Down Expand Up @@ -177,6 +178,7 @@ internal void OnAvatarClear()
m_locomotionOffset = Vector3.zero;
m_emoteActive = false;
m_moving = false;
m_locomotionOverride = false;
m_hipsToPlayer = Vector3.zero;
m_avatarHips = null;
m_viewPointHeight = 1f;
Expand Down Expand Up @@ -282,7 +284,7 @@ internal void OnPlayspaceScale()

void OnIKPreUpdate()
{
bool l_legsOverride = false;
bool l_locomotionOverride = false;

m_ikWeight = m_vrIk.solver.IKPositionWeight;
m_locomotionWeight = m_vrIk.solver.locomotion.weight;
Expand All @@ -300,31 +302,35 @@ void OnIKPreUpdate()
m_vrIk.solver.locomotion.weight = 0f;
m_vrIk.solver.leftLeg.useAnimatedBendNormal = true;
m_vrIk.solver.rightLeg.useAnimatedBendNormal = true;
l_legsOverride = true;
l_locomotionOverride = true;
}
if(m_ikOverrideFly && MovementSystem.Instance.flying)
{
m_vrIk.solver.locomotion.weight = 0f;
m_vrIk.solver.leftLeg.useAnimatedBendNormal = true;
m_vrIk.solver.rightLeg.useAnimatedBendNormal = true;
l_legsOverride = true;
l_locomotionOverride = true;
}
if(m_ikOverrideJump && !m_grounded && !MovementSystem.Instance.flying)
{
m_vrIk.solver.locomotion.weight = 0f;
m_vrIk.solver.leftLeg.useAnimatedBendNormal = true;
m_vrIk.solver.rightLeg.useAnimatedBendNormal = true;
l_legsOverride = true;
l_locomotionOverride = true;
}
}

bool l_solverActive = !Mathf.Approximately(m_vrIk.solver.IKPositionWeight, 0f);
if(l_legsOverride && l_solverActive && m_followHips && (!m_moving || (m_poseState == PoseState.Proning)) && m_inVR && !BodySystem.isCalibratedAsFullBody)
if(l_locomotionOverride && l_solverActive && m_followHips && (!m_moving || (m_poseState == PoseState.Proning)) && m_inVR && !BodySystem.isCalibratedAsFullBody)
{
m_vrIk.solver.plantFeet = false;
ABI_RC.Systems.IK.IKSystem.VrikRootController.enabled = false;
PlayerSetup.Instance._avatar.transform.localPosition = m_hipsToPlayer;
}

if(m_locomotionOverride && !l_locomotionOverride)
m_vrIk.solver.Reset();
m_locomotionOverride = l_locomotionOverride;
}

void OnIKPostUpdate()
Expand Down

0 comments on commit 3940802

Please sign in to comment.