- Home /
 
 
               Question by 
               uberalles · Feb 01, 2014 at 09:50 PM · 
                rotationtransformquaternionlerp  
              
 
              Need to check transform.rotation
I'm using a quick Quaternion.Lerp to turn a human character around before he starts running in that direction. Here's how I setup the Lerp ( this is within an Update() ):
  if(rotating)
     {
         Vector3 pos = nav.destination - transform.position;
         Quaternion newRot = Quaternion.LookRotation(pos);
         Debug.Log("tranform: "+ transform.rotation + " newRotation: " + newRot);
     if(transform.rotation == newRot)
     Debug.Log("FACING THE RIGHT DIRECTION !!!!!!!!!!!!!!!!!!!!!");
     if(transform.rotation != newRot)
                 transform.rotation = Quaternion.Lerp(transform.rotation, newRot, .0005f);
                 else
                 {
                     rotating = false;
                     if(nav.remainingDistance > nav.stoppingDistance)
                     {
                         moving = true;
                     }
                 }
             }
 
               The debug that states when the transform is facing in the right direction never hits yet from the other debug I can see that transform.rotation will be equal to newRot variable. Is there a better way to check when the object is facing the correct direction? Thanks in advance.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by getyour411 · Feb 01, 2014 at 10:02 PM
Try something like this
         Vector3 dir = (myTarget.position - myTransform.position).normalized;
         float direction = Vector3.Dot(dir, myTransform.forward);
 
 if(direction > .6f) //
 
               Adjust .6 to meet your needs
Your answer