# Unity look at rotation on one axis only problem

Hey I would like an object to look at another object only at one axis, when I rotate the white cube all around the gray cube (gray has look at script), the gray cube flips as soon as the target passes the middle and is on the right side. How can I fix this, so that rotation is normal.

Below is when the cube (target, white).

Below is what happens when the cube (target) passes on the other side, as you can see by the texture the gray cube flips horizontally.

Below is how it should be (texture shows difference)

Code:

    Quaternion lookAngle = Quaternion.LookRotation(targetPos, Vector3.up);


• This sounds very similar to the problem solved in "Lookrotation of a gameObject in just one axis" - would the solution there be useful to you? – DMGregory Apr 1 '17 at 13:04
• I'm not sure if it would solve the problem, but I found the solution, I'll post in abit – Vadim Tatarnikov Apr 1 '17 at 13:09

Solved it, the working code is below:

Vector3 dif = targetPos - transform.position;
dif.z = 0;

Quaternion lookAngle = Quaternion.LookRotation(dif, transform.up);