Rotating an Object (To Face Another Object) Only on X and Y Axis

Hello,
I did some research on the topic and I couldn’t understand any answers so I decided to ask here. I would like my character to face the object, here is that part of the script:

function lookAt ()
{
	var rotation = Quaternion.LookRotation(Target.position - transform.position);
	transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}

The problem comes when “Target” gets to close to this object and it leans slightly back to deal with the Y axis, I thought if it would only face the objects X and Z axis it might fix this.
Any help is appreciated.
Thanks.

Untested, but this should work:

var delta = target.position - transform.position;
var angle = Math.Atan2(delta.y, delta.x) * Mathf.Rad2Deg;
var rotation = Quaternion.Euler(0, angle, 0);

Hello, the answer is pretty simple:

function lookAt() {
	// Store the other object's position in a temporary variable
	var temp = Target.position;
	// Deflate it's x and z coordinate
	temp.x = temp.z = uint.MinValue;

	var lookRotation = Quaternion.LookRotation (temp);
	transform.rotation = Quaternion.Slerp (transform.rotation, lookRotation, Damping * Time.deltaTime);
}

did you try something like:

transform.LookAt(new Vector3(Target.position.x, Target.position.y, transform.position.z));

OR

Target.LookAt(new Vector3(transform.position.x, transform.position.y, Target.position.z));

Depends on what should look at what.