AI rotation issue

I have the script :

var target : Transform;
var damp = 5.0;
var speed = 3.0;

function Start () {
	// Auto setup player as target through tags
	if (target == null  GameObject.FindWithTag("Player"))
		target = GameObject.FindWithTag("Player").transform;
}

function Update () {
	if (target  Vector3.Distance(transform.position, target.position) < 30) {
		var rotate = Quaternion.LookRotation(target.position - transform.position);
		transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
		
		var controller : CharacterController = GetComponent(CharacterController);
		
		var forward : Vector3 = transform.TransformDirection(Vector3.forward);
		controller.SimpleMove(forward * speed);
	}
	
	else if (target  Vector3.Distance(transform.position, target.position) > 30) {
		
	}
}

and I want the enemy to only rotate around the y axis. How would I do this?

Replace target.position with a Vector3 that copies the X and Z values from target.position, but uses the Y value from transform.position.

var rotate = Quaternion.LookRotation(Vector3(target.position.x, transform.position.y, target.position.z) - transform.position);

There ya go. Just replace the existing “LookRotation” line with this one, and you should be good to go.

Thanks a bunch!!!