Problem with Quaternion.FromToRotation ??

I am trying to rotate one mesh plane to turn toward another mesh plane, and it mostly works, but there seems to be a glitch when it is rotated in the 4th quadrant.

Here is the actual script I am using:

var target: Transform;

function Update(){
	var wantRot: Quaternion = Quaternion.FromToRotation (transform.position, target.position);
	transform.eulerAngles.z = (wantRot.eulerAngles.z-45);
}

Here is the test demo:

http://www.bunzaga.com/Unity_Tests/Demo_2d_1/WebPlayer/WebPlayer.html

If you slowly rotate the mouse around the center of the screen, you can see it almost works great, but if you rotate around the 4th quadrant, it seems like the center mesh flips for a moment, then returns back to normal.

Let me know if there is something I am doing wrong, or if there is a better option to do this, etc.

EDIT: It looks like it is when the eulerZ == 130 to 145…

Ahh I think I found my issue. I was doing this from the ‘front’ direction. I guess the FromToRotation likes to have ‘up’ being +1 on the y axis.

Although I was able to reposition the camera to be above the planes, and rotated them to lay flat, I would still like a way to do this from the ‘front’ view, if anyone has a solution? Also, I had to use the Quaternion.LookRotation function instead of FromToRotation.

What is the best way to do this, from the front perspective?

Ok I found the answer. I had to just figure it out using Mathf.Atan2 rather than using a built in function.

public var target: Transform;

private var wantDir: Vector3;
private var wantRot: float;

function Update(){	
	wantDir = target.position - transform.position;
	wantRot = ((Mathf.Atan2(wantDir.y, wantDir.x) * Mathf.Rad2Deg)-90);
	transform.eulerAngles.z = wantRot;
}

Works like a charm. (updated original link)