Question by 
               gpiedimonte · Nov 04, 2015 at 12:59 PM · 
                rotation axisquaternions  
              
 
              How to rotate a local axis of an object to another object?
Using the following code I can rotate the local Z axis to another GameObject.
 /// <summary>
 /// Faces local Z axis to another target object.
 /// </summary>
 /// <param name="target">Target.</param>
 private void FaceTo(GameObject target){
     float damping = 0.03f;
     var lookPos = target.transform.position - transform.position;
 
     var rotation = Quaternion.LookRotation(lookPos);
 
     transform.rotation = 
          Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); 
 }
 
               the result during the Update method is the following: 
Now I need to face to the object using another axis, not the Z axis of my object; for example I would use the positive X axis for obtain this result: 
How can I modify my script? Unfortunately I do not know the math of Quaternions and Vectors and I'm a bit confused.
 
                 
                screenshot-2015-11-04-102547.png 
                (31.8 kB) 
               
 
                
                 
                screenshot-2015-11-04-102412.png 
                (57.1 kB) 
               
 
              
               Comment
              
 
               
              Your answer