- Home /
Change orientation / rotation of NavMeshAgent, Trig question?
I have a NavMeshAgent that uses the "Agent" and "Locomotion" scripts from the Mecanim samples. I'm trying to figure out how to turn the agent toward a particular orientation, without making him change his position, but all the while still performing the "turn in place" animation.
The turning animation happens when the "angle" variable is greater than 0.
The following snippet runs until the NavMesh agent reaches its destination, but I'm not clear on what the math is doing here:
float speed = agent.desiredVelocity.magnitude;
Vector3 velocity = Quaternion.Inverse(transform.rotation) * agent.desiredVelocity;
float angle = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f;
locomotion.Do(speed, angle);
I'm not sure what the agents velocity has to do with the turning angle. I know that there are several "turning" animations - i.e. quarter turn, half turn, etc - that get played based on the magnitude of "angle", but again I'm unclear what that has to do with the agent's velocity.
At the end of the day, all I want to do is turn the agent in place, toward the camera, using the most appropriate turn-in-place animation.
Your answer
Follow this Question
Related Questions
Animator component prevents NavMeshAgent from disabling/enabling dynamically 0 Answers
Animator and navmesh component on a parent of an FBX 0 Answers
weird _navAgent.desiredVelocity.magnitude changes.... 0 Answers
NavMeshAgent animation - sliding 2 Answers
Click to move, navAgent and mecanim = animation playing too early 0 Answers