Skip to content

Commit

Permalink
Add PointAt TaskAction, Add description to rotation sample scene
Browse files Browse the repository at this point in the history
  • Loading branch information
lenalinke committed Aug 11, 2024
1 parent cfbd3b5 commit 27fb2a3
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ AnimatorState:
m_Name: Idle | Walk
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 2573289453217930312}
m_Transitions: [{fileID: 2573289453217930312}]
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
Expand Down Expand Up @@ -371,15 +370,17 @@ BlendTree:
m_Name: Blend Tree
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: -3772180338694805941, guid: c3b74a83e3d65e54f8af4de2bf2a139c, type: 3}
m_Motion: {fileID: -3772180338694805941, guid: c3b74a83e3d65e54f8af4de2bf2a139c,
type: 3}
m_Threshold: 0
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: speed
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -3351673834204083825, guid: fe48fe4cd231c0c488b9c6b1c5f7e250, type: 3}
m_Motion: {fileID: -3351673834204083825, guid: fe48fe4cd231c0c488b9c6b1c5f7e250,
type: 3}
m_Threshold: 1.3988087
m_Position: {x: 0, y: 0}
m_TimeScale: 1
Expand Down Expand Up @@ -619,7 +620,8 @@ BlendTree:
m_DirectBlendParameter: Speed
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -3772180338694805941, guid: c3b74a83e3d65e54f8af4de2bf2a139c, type: 3}
m_Motion: {fileID: -3772180338694805941, guid: c3b74a83e3d65e54f8af4de2bf2a139c,
type: 3}
m_Threshold: 0
m_Position: {x: 0, y: 0}
m_TimeScale: 1
Expand Down Expand Up @@ -704,6 +706,60 @@ AnimatorController:
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
- m_Name: Speed
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: RotationDirection
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: ShakeHead
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: WaveLeft
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: WaveRight
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: NoAnimation
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: PointingLeft
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: PointingRight
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: IsRotating
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
Expand Down Expand Up @@ -820,7 +876,8 @@ AnimatorState:
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: -4646348500681454183, guid: 7068b1601249e6046b5d8a08e0044cc0, type: 3}
m_Motion: {fileID: -4646348500681454183, guid: 7068b1601249e6046b5d8a08e0044cc0,
type: 3}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
Expand Down Expand Up @@ -872,7 +929,8 @@ AnimatorState:
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: -4646348500681454183, guid: 7068b1601249e6046b5d8a08e0044cc0, type: 3}
m_Motion: {fileID: -4646348500681454183, guid: 7068b1601249e6046b5d8a08e0044cc0,
type: 3}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ private void Awake()
}
}

/// <summary>
/// Get the agent component of the game object
/// </summary>
/// <returns>The agent component</returns>
public Agent GetAgent()
{
return GetComponent<Agent>();
}

public override void UpdateTaskSystem()
{
foreach (var taskManager in taskManagers.Values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,44 @@ public void ActivateOrDeactivateAdaptiveGaze(bool shouldStartOrStop, int priorit
AgentBaseTask adaptiveGazeTask = new AgentAdaptiveGazeTask(shouldStartOrStop);
scheduleTaskSystem.ScheduleTask(adaptiveGazeTask, priority, "Head");
}

/// <summary>
/// Use this function to make the agent point at a target object with one arm
/// If the target is behind the agent, the agent will first rotate towards the target
/// </summary>
/// <param name="agent"></param>
/// <param name="target"></param>
/// <param name="aimLeftArm"></param>
/// <param name="aimRightArm"></param>
/// <param name="aimAtTime"></param>
/// <param name="priority"></param>
/// <returns></returns>
public AgentBaseTask PointAt(GameObject target, bool aimLeftArm = false, bool aimRightArm = false, int aimAtTime = 5, int priority = 0)
{
AgentAnimationTask pointing = null;
Agent agent = scheduleTaskSystem.GetAgent();
// Add rotation before pointing if target is behind agent
Vector3 directionToTarget = target.transform.position - agent.transform.position;
float angleToTarget = Vector3.Angle(agent.transform.forward, directionToTarget);

// If the target is behind the agent (angle greater than 90 degrees)
if (angleToTarget > 90 && angleToTarget < 270)
{
// Schedule a rotation task towards the target
AgentRotationTask rotationTask = new AgentRotationTask(target);
scheduleTaskSystem.ScheduleTask(rotationTask, priority, "Left Arm");
}
if (aimLeftArm)
{
pointing = new AgentAnimationTask("PointingLeft", aimAtTime, "", "Left Arm", target);
scheduleTaskSystem.ScheduleTask(pointing, priority, "Left Arm");
}
else if (aimRightArm)
{
pointing = new AgentAnimationTask("PointingRight", aimAtTime, "", "Right Arm", target);
scheduleTaskSystem.ScheduleTask(pointing, priority, "Right Arm");
}
return pointing;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -769,13 +769,13 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1749989800}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0.31255558, z: -0, w: 0.9498995}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.05, y: 1.5933, z: 3.7}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: -36.427, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1749989803
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1135,11 +1135,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 700674713753034054, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3}
propertyPath: m_LocalRotation.y
value: -0
value: 0
objectReference: {fileID: 0}
- target: {fileID: 700674713753034054, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3}
propertyPath: m_LocalRotation.z
value: -0
value: 0
objectReference: {fileID: 0}
- target: {fileID: 700674713753034054, guid: 2962848ab48f0e4459691ff3d6d1eed0, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ protected override void Start()
taskSystem.ScheduleTask(pointingRight, 0, "Right Arm");
}
}
// If you want the agent to rotate towards a target before pointing, you can use the PointAt TaskAction
AgentBaseTask pointAt = taskSystem.Tasks.PointAt(target, true, false, aimAtTime);

// or to rotate without using TaskActions you can use the AgentRotationTask
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1273,20 +1273,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
title:
description: 'This scene demonstrates how to schedule walking tasks so that the
agent navigates a series of waypoints.
The script on the Controller object
issues walking tasks to the agent on startup.
Use the scene view during
play mode to inspect the scene freely while the agent is walking around.
If
Objects are changed in the scene: Select the GameObject "NavMesh Surface" and
bake the NavMesh again before running the scene.'
description: "This scene demonstrates the different types of rotation.\r\n\nThe
agent first rotates towards a target object (here the first waypoint), then towards
a coordinate (the coordinates of the second waypoint), \r\nand finally rotates
by 90\xB0 and then towards 90\xB0."
type: 0
url:
--- !u!4 &1264251852
Expand Down
10 changes: 6 additions & 4 deletions Documentation/manual/task-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Currently, the following tasks exist and can already be used:
- <xref:i5.VirtualAgents.AgentTasks.AgentAnimationTask>: Play animations on the agent
- <xref:i5.VirtualAgents.AgentTasks.AgentMovementTask>: Let the agent walk to a given location or follow an object dynamically
- <xref:i5.VirtualAgents.AgentTasks.AgentWaitTask>: Let the agent wait for a specific amount of time
- <xref:i5.VirtualAgents.AgentTasks.AgentRotationTask>: Let the agent rotate to a specific angle, towards a specific object or towards coordinates
- <xref:i5.VirtualAgents.AgentTasks.AgentPickUpTask>: Let the agent pickup an object next to them
- <xref:i5.VirtualAgents.AgentTasks.AgentDropTask>: Let the agent drop an object or all objects that the agent is holding
- <xref:i5.VirtualAgents.AgentTasks.AgentAdaptiveGazeTask>: Starts or stops the [adaptive gaze](adaptive-gaze.md) feature.
Expand Down Expand Up @@ -59,10 +60,10 @@ In order to keep the code brief and understandable, it is not always necessary t
For common actions, it is also possible to call one of the shortcut functions on the agent.
Currently, the following shortcut functions exist:
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.GoTo*>
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.GoTo(Vector3,System.Int32)>: Let the agent walk to the specified coordinates.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.GoTo(Transform,Vector3,System.Int32)>: Let the agent walk to the specified transform of an object in the scene.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.GoTo(Vector3,System.Int32)>: Let the agent walk and turn to the specified coordinates.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.GoTo(Transform,Vector3,System.Int32)>: Let the agent walk and turn to the specified transform of an object in the scene.
You can add an optional offset so that the agent does not run into the object but stops next to it.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.GoTo(GameObject,Vector3,System.Int32,System.Boolean)>: Let the agent walk to the specified object in the scene.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.GoTo(GameObject,Vector3,System.Int32,System.Boolean)>: Let the agent walk and turn to the specified object in the scene.
You can add an optional offset so that the agent does not run into the object but stops next to it.
The agent can also follow an object dynamically, so that the agent will follow the object until it is reached. Partial incomplete paths will be allowed, when that option is enabled.

Expand All @@ -76,4 +77,5 @@ Specifying a GameObject as an `aimTarget` for the animation, will start inverse
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.DropItem*>: Drop the specified item if it is currently hold be the agent, if no item is specified, all items are dropped.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.GoToAndDropItem*>: Schedules an GoTo Task that makes the agent walk to the specified coordinates or transform before dropping the specified item or all items, if no item is specified.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.ActivateOrDeactivateAdaptiveGaze*>: Start or stops adaptive gazing until it is stopped or started again. This is realized with a task that only runs once. This also automatically adds a <xref:i5.VirtualAgents.AdaptiveGaze> component if the agent doesn't have one.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.StartAdaptiveGazeForTime*>: Schedule a task that starts adaptive gazing for the specified time and then deactivates it by scheduling a wait task between a start and stop task.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.StartAdaptiveGazeForTime*>: Schedule a task that starts adaptive gazing for the specified time and then deactivates it by scheduling a wait task between a start and stop task.
- <xref:i5.VirtualAgents.ScheduleBasedExecution.TaskActions.PointAt*>: Point at the specified object with the left or right arm. If the object is behind the agent, the agent will turn around to point at it.

0 comments on commit 27fb2a3

Please sign in to comment.