- Home /
Lerp to face target?
How do i use lerp, to make an ai enemy face a target object smoothly? - Thanks.
Comment
Best Answer
Answer by Ashkan_gc · Jul 03, 2012 at 10:19 PM
First get the vector from yourself to enemy by doing something like this Vector3 dirVector = enemy.transform.position - transform.position;
Then get the quaternion which looks towar this by Quaternion.LookRotation or similar stuff. then just use Quaternion.Lerp or Slerp to rotate from your first direction to the target one.
Wiki
Answer by idunlop_oefun · Jul 03, 2012 at 10:21 PM
Something like this:
t += Time.deltaTime; // t is a float (starts at 0.0f)
if (t > 1.0f) t = 1.0f; // when t reaches 1.0f your gameObject will be at the dest rotation
Quaternion start = transform.rotation; // ai start rotation
Quaternion dest; // some other rotation
transform.rotation = Quaternion.Lerp(start, dest, t);
Your answer
Follow this Question
Related Questions
interpolate a move variable 0 Answers
Mathf.Lerp happens instantly 2 Answers
Execute function with momentary input 1 Answer