Problem with AI turret.

Hello all I am uisng the Sentry script from the FPS game tutorial in a 2D sidescroller that I am working on. For some reason It is looking for the character in the Y axis.

For example. I place the sentry in front of me and it will not track my movement, if i place the sentry above me it will track my movement fine. I have tried playing around with the script and cannot seem to get it to wotk the way i would like it to.

The code from the Sentry.JS is below.

var attackRange = 30.0;
var shootAngleDistance = 10.0;
var target : Transform;

function Start () {
	if (target == null  GameObject.FindWithTag("Player"))
		target = GameObject.FindWithTag("Player").transform;
}

function Update () {
	if (target == null)
		return;
	
	if (!CanSeeTarget ())
		return;
	
	// Rotate towards target	
	var targetPoint = target.position;
	var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
	transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);

	// If we are almost rotated towards target - fire one clip of ammo
	var forward = transform.TransformDirection(Vector3.forward);
	var targetDir = target.position - transform.position;
	if (Vector3.Angle(forward, targetDir) < shootAngleDistance)
		SendMessage("Fire");
}

function CanSeeTarget () : boolean
{
	if (Vector3.Distance(transform.position, target.position) > attackRange)
		return false;
		
	var hit : RaycastHit;
	if (Physics.Linecast (transform.position, target.position, hit))
		return hit.transform == target;

	return false;
}

I am using the standard XYZ setup, so y is up, X is left and right (Side Scroller) and Z is Depth which can be ignored.

Any help would be appriciated. Thanks.

Just a guess, but there could be a problem with Quaternion.LookRotation. It’s best if you pass the axis of rotation as the second parameter. If the sentry rotates completely in the game plane then this would be the Z axis.