Skip to content

Commit

Permalink
Add offset between left and right foot
Browse files Browse the repository at this point in the history
  • Loading branch information
lenalinke committed Oct 5, 2024
1 parent 3a69267 commit 2e67b66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public override void StartExecution(Agent agent)

animator.SetBool("Sitting", sitting);

agent.StartCoroutine(FadeIK(true));
agent.StartCoroutine(FadeIK(agent, true));
}
// case: standing up
else
{
animator.SetBool("Sitting", false);
agent.StartCoroutine(FadeIK(false));
agent.StartCoroutine(FadeIK(agent, false));

Debug.Log("Standing up");
}
Expand All @@ -120,13 +120,14 @@ public override void StartExecution(Agent agent)
/// <param name="agent">The agent</param>
/// <param name="fadeIn">Whether to fade in or fade out the IK, etc. In other words: whether the agent sits down (true) or stands up (false)</param>
/// <returns></returns>
private IEnumerator FadeIK(bool fadeIn)
private IEnumerator FadeIK(Agent agent, bool fadeIn)
{
float duration = animationDuration;
float time = 0;
float startWeight = fadeIn ? 0 : 1;
float endWeight = fadeIn ? 1 : 0;
Vector3 ikPosition = fadeIn ? footrest : feetPosition;
Vector3 curIkPosition = ikPosition;

while (time < duration)
{
Expand All @@ -136,16 +137,19 @@ private IEnumerator FadeIK(bool fadeIn)
rightLegIK.weight = Mathf.Lerp(startWeight, endWeight, time / duration);

// move ik target when standing up, to avoid, that the agent suddenly fully stretches their legs
leftLegIKTarget.transform.position = rightLegIKTarget.transform.position =
curIkPosition =
fadeIn ? ikPosition : Vector3.Lerp(footrest, feetPosition, time / duration);
leftLegIKTarget.transform.position = curIkPosition - agent.transform.right * 0.08f;
rightLegIKTarget.transform.position = curIkPosition + agent.transform.right * 0.08f;

spineAim.weight = Mathf.Lerp(startWeight, endWeight, time / duration);
hipConstraint.weight = Mathf.Lerp(startWeight, endWeight, time / duration);
hipIKTarget.transform.position = sitPosition;
yield return null;
}
rightLegIK.gameObject.transform.position = leftLegIK.gameObject.transform.position = feetPosition;
leftLegIKTarget.transform.position = rightLegIKTarget.transform.position = ikPosition;
leftLegIKTarget.transform.position = ikPosition - agent.transform.right * 0.08f;
rightLegIKTarget.transform.position = ikPosition + agent.transform.right * 0.08f;
hipIKTarget.transform.position = sitPosition;

finished = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,39 +463,39 @@ PrefabInstance:
m_Modifications:
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalPosition.x
value: -0.089982
value: -0.10176502
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalPosition.y
value: 1.445
value: 1.436
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalPosition.z
value: -0.515
value: -0.46002823
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalRotation.w
value: 0.99941254
value: 0.86963195
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalRotation.x
value: -0.021069733
value: -0.0070600905
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalRotation.y
value: 0.013028288
value: 0.49268192
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalRotation.z
value: 0.023685886
value: 0.030904867
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -2.449
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 1.436
value: 59.009
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
Expand Down Expand Up @@ -2935,7 +2935,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 6700788506347371110, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3}
propertyPath: m_Data.m_MaintainTargetPositionOffset
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6700788506347371110, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3}
propertyPath: m_Data.m_MaintainTargetRotationOffset
Expand Down Expand Up @@ -3015,7 +3015,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 7390127396291110507, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3}
propertyPath: m_Data.m_MaintainTargetPositionOffset
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7390127396291110507, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3}
propertyPath: m_Data.m_MaintainTargetRotationOffset
Expand Down

0 comments on commit 2e67b66

Please sign in to comment.