From 5f43fc2442a0b2fe1ad30f95f38daa2969be5e7f Mon Sep 17 00:00:00 2001 From: Lena Linke <130255332+lenalinke@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:35:27 +0200 Subject: [PATCH] Fix bug that would change IK target positions if sitting was preceded by GoTo Task --- .../AgentStandardController.controller | 18 +- .../FundamentalAgentTasks/AgentSittingTask.cs | 14 +- .../Sitting Sample/AgentSittingController.cs | 7 +- .../Sitting Sample/Sitting Sample.unity | 161 ++++++++++++++---- 4 files changed, 153 insertions(+), 47 deletions(-) diff --git a/Assets/Virtual Agents Framework/Runtime/Animations/AgentStandardController.controller b/Assets/Virtual Agents Framework/Runtime/Animations/AgentStandardController.controller index b7d398f..835393e 100644 --- a/Assets/Virtual Agents Framework/Runtime/Animations/AgentStandardController.controller +++ b/Assets/Virtual Agents Framework/Runtime/Animations/AgentStandardController.controller @@ -552,7 +552,7 @@ AnimatorState: - {fileID: -4743300286174424125} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} - m_IKOnFeet: 1 + m_IKOnFeet: 0 m_WriteDefaultValues: 1 m_Mirror: 0 m_SpeedParameterActive: 0 @@ -700,49 +700,49 @@ AnimatorController: m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: ShakeHead m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: WaveLeft m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: WaveRight m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: NoAnimation m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: PointingLeft m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: PointingRight m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Sitting m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer diff --git a/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentSittingTask.cs b/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentSittingTask.cs index 986c984..8f36952 100644 --- a/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentSittingTask.cs +++ b/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentSittingTask.cs @@ -77,10 +77,15 @@ public override void StartExecution(Agent agent) hipConstraint = agent.transform.Find("AnimationRigging/CharacterRig/Hip Constraint").GetComponent(); hipIKTarget = hipConstraint.transform.Find("Hip IK_target").gameObject; + // set the target positions to the agents current position + leftLegIK.transform.position = rightLegIK.transform.position = agent.transform.position; + hipIKTarget.transform.position = agent.transform.position; + // case: sitting down if (currentState) { agent.transform.rotation = Chair.transform.rotation; + Debug.Log("Setting footrest and sitposition"); leftLegIKTarget.transform.position = rightLegIKTarget.transform.position = footrest; hipIKTarget.transform.position = sitPosition; @@ -118,17 +123,24 @@ private IEnumerator FadeIKAndPosition(Agent agent, bool fadeIn) Vector3 endPosition = fadeIn ? sitPosition : feetPosition; while (time < duration) { + rightLegIK.gameObject.transform.position = leftLegIK.gameObject.transform.position = footrest; time += Time.deltaTime; leftLegIK.weight = Mathf.Lerp(startWeight, endWeight, time / duration); rightLegIK.weight = Mathf.Lerp(startWeight, endWeight, time / duration); + + // move ik target when standing up, to avoid, that the agent suddenly completely stretches their feet + leftLegIKTarget.transform.position = fadeIn + ? rightLegIKTarget.transform.position = ikPosition + : rightLegIKTarget.transform.position = Vector3.Lerp(footrest, feetPosition, time / duration); + spineAim.weight = Mathf.Lerp(startWeight, endWeight, time / duration); hipConstraint.weight = Mathf.Lerp(startWeight, endWeight, time / duration); agent.transform.position = Vector3.Lerp(startPosition, endPosition, time / duration); - leftLegIKTarget.transform.position = rightLegIKTarget.transform.position = ikPosition; hipIKTarget.transform.position = sitPosition; yield return null; } + rightLegIK.gameObject.transform.position = leftLegIK.gameObject.transform.position = footrest; leftLegIKTarget.transform.position = rightLegIKTarget.transform.position = ikPosition; hipIKTarget.transform.position = sitPosition; finished = true; diff --git a/Assets/Virtual Agents Framework/Samples/Sitting Sample/AgentSittingController.cs b/Assets/Virtual Agents Framework/Samples/Sitting Sample/AgentSittingController.cs index 6bb529d..d8cceb0 100644 --- a/Assets/Virtual Agents Framework/Samples/Sitting Sample/AgentSittingController.cs +++ b/Assets/Virtual Agents Framework/Samples/Sitting Sample/AgentSittingController.cs @@ -17,6 +17,7 @@ protected override void Start() AgentSittingTask sittingTaskStool = new AgentSittingTask(Stool, SittingDirection.SITDOWN); + // AgentSittingTask sittingTaskStool2 = new AgentSittingTask(Stool, SittingDirection.SITDOWN); AgentSittingTask standingTaskStool = new AgentSittingTask(Stool, SittingDirection.STANDUP); // add a sitting task @@ -24,8 +25,10 @@ protected override void Start() taskSystem.Tasks.WaitForSeconds(3); Debug.Log("2nd Sitting Task Scheduled"); taskSystem.ScheduleTask(standingTask); - Vector3 destination = Stool.transform.Find("FeetPosition").position; - taskSystem.Tasks.GoTo(destination); + + GameObject destination = Stool.transform.Find("FeetPosition").gameObject; + taskSystem.Tasks.GoTo(destination, Vector3.zero, 0, true); + taskSystem.Tasks.WaitForSeconds(1); taskSystem.ScheduleTask(sittingTaskStool); taskSystem.Tasks.WaitForSeconds(3); taskSystem.ScheduleTask(standingTaskStool); 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 6a16f36..37bfb5b 100644 --- a/Assets/Virtual Agents Framework/Samples/Sitting Sample/Sitting Sample.unity +++ b/Assets/Virtual Agents Framework/Samples/Sitting Sample/Sitting Sample.unity @@ -467,7 +467,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3} propertyPath: m_LocalPosition.y - value: 1.438 + value: 1.417 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3} propertyPath: m_LocalPosition.z @@ -547,6 +547,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3} insertIndex: -1 addedObject: {fileID: 471645978} + - targetCorrespondingSourceObject: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3} + insertIndex: -1 + addedObject: {fileID: 1313266857} - targetCorrespondingSourceObject: {fileID: -8679921383154817045, guid: 0cdb6d1ca77e8644ba96b04bb986b127, type: 3} insertIndex: -1 addedObject: {fileID: 717296191} @@ -582,7 +585,7 @@ Transform: m_GameObject: {fileID: 471645977} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.077, y: -1.41, z: 0.401} + m_LocalPosition: {x: -0.079, y: -1.454, z: 0.399} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1053,7 +1056,7 @@ Transform: m_GameObject: {fileID: 717296190} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.043, y: -0.92, z: -0.039} + m_LocalPosition: {x: -0.0424, y: -0.9066, z: -0.0384} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1200,6 +1203,11 @@ Transform: m_Children: [] m_Father: {fileID: 1294797797} m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0} +--- !u!4 &875228835 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 5712777125262725549, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + m_PrefabInstance: {fileID: 1023428232005854918} + m_PrefabAsset: {fileID: 0} --- !u!4 &1105237718 stripped Transform: m_CorrespondingSourceObject: {fileID: 8825230413500745420, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} @@ -1500,13 +1508,13 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1165018408} serializedVersion: 2 - m_LocalRotation: {x: 0.22875227, y: -0.6690833, z: 0.22875227, w: 0.6690833} - m_LocalPosition: {x: 1.7, y: 2.7, z: -0.4} + m_LocalRotation: {x: 0.24587631, y: -0.66298175, z: 0.24587631, w: 0.66298175} + m_LocalPosition: {x: 1.913, y: 1.827, z: -0.4} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 37.75, y: -90, z: 0} + m_LocalEulerAnglesHint: {x: 40.696, y: -90, z: 0} --- !u!1 &1264251850 GameObject: m_ObjectHideFlags: 0 @@ -1610,6 +1618,37 @@ Transform: - {fileID: 1154611548} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1313266856 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1313266857} + m_Layer: 6 + m_Name: Footrest + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1313266857 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1313266856} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.064, y: -1.215, z: 0.299} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 724669920} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1351748437 GameObject: m_ObjectHideFlags: 0 @@ -1828,7 +1867,7 @@ Transform: m_GameObject: {fileID: 1651691536} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.055, y: 0.291, z: 0.131} + m_LocalPosition: {x: -0.0208, y: 0.2661, z: 0.0546} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1870,28 +1909,6 @@ GameObject: m_CorrespondingSourceObject: {fileID: 6366591362562935619, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} m_PrefabInstance: {fileID: 1023428232005854918} m_PrefabAsset: {fileID: 0} ---- !u!114 &1743031138 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1743031135} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: fff0960ef4ea6e04eac66b4a7fd2189d, type: 3} - m_Name: - m_EditorClassIdentifier: - m_RigLayers: - - m_Rig: {fileID: 0} - m_Active: 1 - - m_Rig: {fileID: 0} - m_Active: 1 - - m_Rig: {fileID: 0} - m_Active: 1 - - m_Rig: {fileID: 0} - m_Active: 1 - m_Effectors: [] --- !u!95 &1743031139 Animator: serializedVersion: 5 @@ -1954,7 +1971,7 @@ Transform: m_GameObject: {fileID: 1779049543} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.141, y: 0.017, z: 0.319} + m_LocalPosition: {x: -0.19, y: 0.017, z: 0.429} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -2201,6 +2218,11 @@ Transform: m_Children: [] m_Father: {fileID: 1294797797} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &1905132563 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 5496834473522196528, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + m_PrefabInstance: {fileID: 1023428232005854918} + m_PrefabAsset: {fileID: 0} --- !u!1 &1969051388 GameObject: m_ObjectHideFlags: 0 @@ -2354,6 +2376,10 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: -5568371526223589888, guid: 089d9e19afbdbbb409e330482cb77501, type: 3} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} - target: {fileID: -745811864070240421, guid: 089d9e19afbdbbb409e330482cb77501, type: 3} propertyPath: m_Materials.Array.data[0] value: @@ -2616,13 +2642,25 @@ PrefabInstance: propertyPath: m_Name value: AgentStandard objectReference: {fileID: 0} + - target: {fileID: 334442996744392338, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 334442996744392338, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 334442996744392338, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} - target: {fileID: 700674713753034054, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} propertyPath: m_RootOrder value: 10 objectReference: {fileID: 0} - target: {fileID: 700674713753034054, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} propertyPath: m_LocalPosition.x - value: -0.03 + value: 0.012 objectReference: {fileID: 0} - target: {fileID: 700674713753034054, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} propertyPath: m_LocalPosition.y @@ -2668,6 +2706,10 @@ PrefabInstance: propertyPath: m_Data.m_SourceObjects.m_Item0.transform value: objectReference: {fileID: 0} + - target: {fileID: 1372687343423552459, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} - target: {fileID: 2054765473159481603, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} propertyPath: m_Enabled value: 1 @@ -2684,10 +2726,26 @@ PrefabInstance: propertyPath: m_Data.m_SourceObjects.m_Item0.transform value: objectReference: {fileID: 2125877258} + - target: {fileID: 3640777756976050664, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3640777756976050664, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3640777756976050664, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6700788506347371110, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} propertyPath: m_Weight value: 0 objectReference: {fileID: 0} + - target: {fileID: 6700788506347371110, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_Data.m_Tip + value: + objectReference: {fileID: 1905132563} - target: {fileID: 6700788506347371110, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} propertyPath: m_Data.m_Hint value: @@ -2720,10 +2778,38 @@ PrefabInstance: propertyPath: m_WarningMessage value: objectReference: {fileID: 0} + - target: {fileID: 7063335175433404670, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7063335175433404670, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7063335175433404670, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7120372243537974172, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.x + value: -3.062 + objectReference: {fileID: 0} + - target: {fileID: 7120372243537974172, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.y + value: 1.567 + objectReference: {fileID: 0} + - target: {fileID: 7120372243537974172, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.z + value: 1.198 + objectReference: {fileID: 0} - target: {fileID: 7390127396291110507, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} propertyPath: m_Weight value: 0 objectReference: {fileID: 0} + - target: {fileID: 7390127396291110507, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_Data.m_Tip + value: + objectReference: {fileID: 875228835} - target: {fileID: 7390127396291110507, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} propertyPath: m_Data.m_Hint value: @@ -2752,7 +2838,15 @@ PrefabInstance: propertyPath: m_Data.m_MaintainTargetRotationOffset value: 0 objectReference: {fileID: 0} - m_RemovedComponents: [] + - target: {fileID: 8066738664786797255, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: + - {fileID: 4270794467423810245, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + - {fileID: 553884212243387729, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + - {fileID: 3430460980174463433, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} + - {fileID: 2213206822084364868, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: @@ -2762,9 +2856,6 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 6366591362562935619, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} insertIndex: -1 addedObject: {fileID: 1743031139} - - targetCorrespondingSourceObject: {fileID: 6366591362562935619, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} - insertIndex: -1 - addedObject: {fileID: 1743031138} m_SourcePrefab: {fileID: 100100000, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3} --- !u!114 &1023428232005854926 MonoBehaviour: