- Home /
 
 
               Question by 
               Flaring-Afro · Aug 19, 2015 at 06:25 AM · 
                coroutinetransform.lookatvector3.slerp  
              
 
              Turning NPC Code not functioning
When I call this coroutine, the NPC fully turns instantly and then the logs keep continuing as he faces me. I have similar code used for flashing an object so I'm not sure why this isn't working.
     IEnumerator TurnNPC(){
         float t = 0;
         Vector3 introVector = m_NPC.transform.position;
         Vector3 endVector = new Vector3(GameObject.Find ("FPSController").transform.position.x, m_NPC.transform.position.y, GameObject.Find ("FPSController").transform.position.z);
 
         while(t<1){
             t+= Time.smoothDeltaTime / turnSpeed;//turnSpeed currently set to 1
             Debug.Log ("turn");
             m_NPC.transform.LookAt (Vector3.Slerp (introVector, endVector,t));
 
             yield return null;
         }
     }
 
              
               Comment
              
 
               
              Anyone have any idea? I never could get it working. I've used both "Slerp" and "Lerp" and both happen instantly and then the console keeps logging "turn" for a couple seconds.
Your answer
 
             Follow this Question
Related Questions
What's stopping 'WaitForSeconds' from working? 1 Answer
Using Time efficiently regardless of current frame rate. 0 Answers
change material on background 4 Answers
OnGUI called after WaitForEndOfFrame on mouseDown events 1 Answer
Lerping alpha with coroutine only lerping first time it is triggered by event 1 Answer