Getting a smooth rotation with Quaterminions slerp in IEnumerator
I'm trying to get an AI character to follow me around and I'm having some trouble getting him to face the object he is chasing. Here's my code.
IEnumerator UpdatePath()
{
float refreshRate = .25f;
while (target != null)
{
hasTarget = true;
Vector3 targetPosition = new Vector3(target.position.x, 0, target.position.z);
pathfinder.SetDestination(targetPosition);
Quaternion rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.time * turnSpeed);
yield return new WaitForSeconds(refreshRate);
}
}
Right now it's very janky. Every time the cycle repeats he snaps to face me instead of getting a smooth turn. is this somethin I should use Update for? or is there a better way.
What do I need to do?
Answer by Arcarno · Jan 06, 2016 at 05:43 PM
For anyone else who is new to unity and is having this problem: I used Lerp which is a faster version of Slerp. My ai now turn in a much smoother fashion.
Your answer
Follow this Question
Related Questions
Enemy rotation while looking. Help. 0 Answers
Can't turn Y axis if terrain Hugging 0 Answers
what is the difference between transform.look at and quaternion.look rotation 0 Answers
Clamping rotation between two angles 0 Answers
How to Rotate Y axis of an Object toward virtual joystick direction 0 Answers