I have following script attached to object that need to be rotated towards target object. It works OK at first glance but if you will rotate object to which this script attached produced rotation will be completely wrong.
I attached project to post. Please help me to figure out whats wrong. 
public var target :Transform;
private var rot :Quaternion;
private var t :float = 1.0;
function Update ()
{
if( Input.GetButtonDown (“Fire1”) )
{
rot = Quaternion.FromToRotation( gameObject.transform.forward, target.position - gameObject.transform.position);
t = 0.1;
}
if( t < 1 )
{
gameObject.transform.rotation = Quaternion.Slerp (gameObject.transform.rotation, rot, t );
t += 0.5 * Time.deltaTime;
}
Debug.DrawLine ( gameObject.transform.position, gameObject.transform.position + gameObject.transform.forward * 100, Color.blue);
Debug.DrawLine ( gameObject.transform.position, target.position, Color.green);
}
543488–19141–$RotationProblem.unitypackage (119 KB)
Welcome
When posting code, please use the code tags
Have you considered using the LookRotation instead of FromToRotation? The FromToRotation may not take into account what is up.
Thanks with LookRotation its working now but I also replaced Slerp by RotateTowards since with Slerp its was working wrong. Still question for me how exactly FromToRotation works and what purpose of it if we have LookRotation.
FromToRotation returns the rotation givin a starting direction and ending rotation. So if your model is pointing forward, and you want the top to be pointing right, you tell it that it’s rotation is Quaternion.FromToRotation(transform.up, transform.right); That makes the top point right.
LookRotation returns the rotation givin a starting rotation of Vector3.forward and an ending rotation to a new position where forward would be if it was facing that position, always keeping the top up. (or you can set that specifically)