Creating a homing missile on 2D, problem with transform.lookat()

I’m trying to make a script for a homing missile, but the rotation when reaching 270 degrees seems to be messed up, my code (for testing purposes right now):

	void FixedUpdate () {
		transform.LookAt (trans.position); //face the target
		transform.rotation = new Quaternion(0,0,transform.rotation.z, transform.rotation.w); //x and y set to 0 since we want to rotate only the z axis
}

But when the z axis reaches 270 degrees it just flips and faces the opposite direction, i dont know what else to try right now.

Construct your sprite so that ‘forward’ is the right side. Then you can do:

Vector3 dir = trans.position - transform.position;
float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);