How to get an object to point at another object

Hi,
I have tried many variatons of code,
inspired from what I had seen on the Unity Ansers forums,
and elsewhere, but I haven’t come up with a solution yet.

What I need is:
an object that points at the player continuously, but that only rotates around its y axis.

I have tried to clamp the transform.LookAt function but without success.
I have also tried various other ways to achieve this, but I got totally confused with the quaternions and euler angles.

I would appreciate a lot , if somebody could point me to the right direction.

Thanks.

A fairly standard solution is (untested):

Vector3 diff = player.position - transform.position;
diff.y = 0;
transform.rotation = Quaternion.LookRotation(diff);

Hi Jesse thanks for the suggestion.
I spent a coupe few hours experimenting, and finaly I came up with

var myTransform : Transform;

function Update () {
transform.LookAt(myTransform);
transform.rotation.z = 0;
transform.rotation.x = 0;
}

I will try your solution if the one above fails.
But for the moment it seems pretty stable.

That won’t actually work right, because transform.rotation is a quaternion, and setting .x and .z doesn’t do what you think it does. Aside from Jesse’s solution, you can do

var lookatPos = targetPos;
lookatPos.y = transform.position.y;
transform.LookAt (lookatPos);

–Eric