transform.LookAt Problem

I have a security camera in my scene with a simple rotate animation. I have written a script so that when the player walks into a trigger collider the animation stops and the camera looks at the target. I have to do it this way because later it will fire projectiles at the enemy.

The problem i am having is it looks at the target with the wrong end of the camera. For some reason it doesn’t matter if i put the camera in a empty game object with the axis point in the directions that i want etc. None of this seems to work so i need a solution in the code. here is my script:

private var player : Transform;

function Start () {
		player = GameObject.FindWithTag("Player").transform;


function Update () {
	var getBool : killZoneJS = gameObject.Find("killZone").GetComponent(killZoneJS);
	if(getBool.killZoneB == true){
		Debug.Log("looking at player?");
		transform.LookAt(Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z));
	} else {

Changing the player.transform.position.y to -transform.position.y doesn’t work either.

Any ideas?

Figured this out a while ago, swear i posted the answer but here is the easiest way.

Lavpatel - your way wont work because i only want it to look ont he y axis.
JMHelpsU - close but it’s easier to do the following.

var target : Transform;

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

I think you can even do it without typing transform before positon since target is already set as a transform in the public var. so ‘traget.position.x’

Hope this helps anyone looking at this question.

//check it


transform.LookAt(Vector3(gameObject.Find("OBJECTNAME").transform.position.x, gameObject.Find("OBJECTNAME").transform.position.y, gameObject.Find("OBJECTNAME").transform.position.z));`
Try using this and tell me how it goes :P instead of using the declare function try using this.

Let me know if there is error and i hope this helped