From 2e67b66b1a1143e71bba53da1741cc579b91b8f5 Mon Sep 17 00:00:00 2001 From: Lena Linke <130255332+lenalinke@users.noreply.github.com> Date: Sat, 5 Oct 2024 02:14:57 +0200 Subject: [PATCH] Add offset between left and right foot --- .../FundamentalAgentTasks/AgentSittingTask.cs | 14 ++++++++----- .../Sitting Sample/Sitting Sample.unity | 20 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentSittingTask.cs b/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentSittingTask.cs index 1057cd9..cd10335 100644 --- a/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentSittingTask.cs +++ b/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentSittingTask.cs @@ -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"); } @@ -120,13 +120,14 @@ public override void StartExecution(Agent agent) /// The agent /// Whether to fade in or fade out the IK, etc. In other words: whether the agent sits down (true) or stands up (false) /// - 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) { @@ -136,8 +137,10 @@ 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); @@ -145,7 +148,8 @@ private IEnumerator FadeIK(bool fadeIn) 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; diff --git a/Assets/Virtual Agents Framework/Samples/Sitting Sample/Sitting Sample.unity b/Assets/Virtual Agents Framework/Samples/Sitting Sample/Sitting Sample.unity index 1afa97d..6566e7a 100644 --- a/Assets/Virtual Agents Framework/Samples/Sitting Sample/Sitting Sample.unity +++ b/Assets/Virtual Agents Framework/Samples/Sitting Sample/Sitting Sample.unity @@ -463,31 +463,31 @@ 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 @@ -495,7 +495,7 @@ PrefabInstance: 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 @@ -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 @@ -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