diff --git a/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentRotationTask.cs b/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentRotationTask.cs index 79edb87..93a0998 100644 --- a/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentRotationTask.cs +++ b/Assets/Virtual Agents Framework/Runtime/Scripts/FundamentalAgentTasks/AgentRotationTask.cs @@ -24,28 +24,32 @@ public class AgentRotationTask : AgentBaseTask, ISerializable /// public float Angle { get; protected set; } + public float Speed { get; protected set; } + /// /// Create an AgentRotationTask using a target object to turn towards /// /// Target object of the rotation task - public AgentRotationTask(GameObject target) + public AgentRotationTask(GameObject target, float speed = 10f) { Vector3 position = target.transform.position; position.y = 0; TargetRotation = Quaternion.LookRotation(position); IsRotationByAngle = false; + Speed = speed; } /// /// Create an AgentRotationTask using the destination coordinates /// /// Coordinates of the rotation task - public AgentRotationTask(Vector3 coordinates) + public AgentRotationTask(Vector3 coordinates, float speed = 10f) { coordinates.y = 0; TargetRotation = Quaternion.LookRotation(coordinates); IsRotationByAngle = false; + Speed = speed; } /// @@ -56,7 +60,7 @@ public AgentRotationTask(Vector3 coordinates) /// /// The angle to rotate by or towards, in degrees /// True if agent should rotate by "angle" degrees, false if the rotation value of the agent should be set to "angle" - public AgentRotationTask(float angle, bool isRotationByAngle = true) + public AgentRotationTask(float angle, float speed= 10f, bool isRotationByAngle = true) { IsRotationByAngle = isRotationByAngle; if (!isRotationByAngle) @@ -67,6 +71,7 @@ public AgentRotationTask(float angle, bool isRotationByAngle = true) { Angle = angle; } + Speed = speed; } /// @@ -84,23 +89,19 @@ public override void StartExecution(Agent agent) TargetRotation = agent.transform.rotation * Quaternion.Euler(0, Angle, 0); } Debug.Log("Rotation started"); - agent.StartCoroutine(Rotate(agent.transform, 10f)); + agent.StartCoroutine(Rotate(agent.transform)); } - private IEnumerator Rotate(Transform transform, float rotationSpeed) + private IEnumerator Rotate(Transform transform) { float time = 0; while (Vector3.Distance(transform.rotation.eulerAngles, TargetRotation.eulerAngles) > 0.01f) { - time += Time.deltaTime/rotationSpeed; //to control the speed of rotation + time += Time.deltaTime/Speed; //to control the speed of rotation // Rotate the agent a step closer to the target transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, time); - //Debug.Log("Rotating..."); - // Wait for the next frame yield return null; } - //if (transform.rotation.eulerAngles == TargetRotation.eulerAngles) - //if (Vector3.Distance(transform.rotation.eulerAngles, TargetRotation.eulerAngles) <= 0.01f) if (Quaternion.Angle(transform.rotation, TargetRotation) <= 0.01f) { FinishTask(); diff --git a/Assets/Virtual Agents Framework/Runtime/Scripts/ScheduleBasedExecution/TaskActions.cs b/Assets/Virtual Agents Framework/Runtime/Scripts/ScheduleBasedExecution/TaskActions.cs index b6ecf38..f9fc36a 100644 --- a/Assets/Virtual Agents Framework/Runtime/Scripts/ScheduleBasedExecution/TaskActions.cs +++ b/Assets/Virtual Agents Framework/Runtime/Scripts/ScheduleBasedExecution/TaskActions.cs @@ -232,12 +232,11 @@ public void ActivateOrDeactivateAdaptiveGaze(bool shouldStartOrStop, int priorit /// 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 /// - /// - /// - /// - /// - /// - /// + /// Target to point at + /// True if the agent should aim with the left arm + /// True if the agent should aim with the right arm + /// How long the agent aims + /// Priority of the task /// public AgentBaseTask PointAt(GameObject target, bool aimLeftArm = false, bool aimRightArm = false, int aimAtTime = 5, int priority = 0) {