Answers for "Rotating on X and Z axis only"
http://answers.unity.com/questions/234642/rotating-on-x-and-z-axis-only.html
The latest answers for the question "Rotating on X and Z axis only"Answer by rutter
http://answers.unity.com/answers/234649/view.html
The simplest thing would be if your two objects are on the same plane.
Barring that, you can at least *pretend* they are by zeroing out the depth axis before calculating your goal rotation:
var displacement = player.position - transform.position;
displacement.z = player.position.z; //pretend objects are at same height
var rotation = Quaternion.LookRotation(displacement); //ed: thanks to Bunny83
By some clever vector multiplication, you could even make that axis-agnostic, but that's probably better left for another day.
If you need more control than that, I suppose you could try something like this:
* Get a rotation from `Slerp()`
* Convert that rotation to its vector form using its [`eulerAngles`][1] property
* Zero out one or more axes
* Convert that back into a rotation using [`Quaternion.Euler()`][2]
Also remembers that if you're using rigidbodies, you can set rotation and position constraints locking them on a particular axis, which is sometimes very handy for 2D simulation.
[1]: http://unity3d.com/support/documentation/ScriptReference/Quaternion-eulerAngles.html
[2]: http://unity3d.com/support/documentation/ScriptReference/Quaternion.Euler.htmlMon, 02 Apr 2012 21:50:05 GMTrutterAnswer by DracoScorpius
http://answers.unity.com/answers/234648/view.html
A solution, if the object this applies to has a Rigidbody, is to freeze the rotation on the Y axis under constraints.Mon, 02 Apr 2012 21:46:07 GMTDracoScorpius