AI stoping problem

I have a problem with 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(Vector3(target.position.x, transform.position.y, target.position.z) - 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) {
		
	}
}

Every time i play my game to test it, one of my enemies get stuck, or both of them get stuck. they just randomly stop. ill put a render of my game in this post if needed.

Have you tried any debugging at all yet? For instance, if you Debug.Logged “I am attacking” inside:

if (target  Vector3.Distance(transform.position, target.position) < 30){

Does it still log “I am attacking” when the AI stops or gets stuck?

Also, whats the point of the else-if if you’re not doing anything in it?

no, it works, but if it gets too high off of the ground or something like that, it just stops moving. the else if is jut there in case i want to do something in the future there

a) Why is it going up into the air?

b) If it goes too high off the ground, couldn’t it be that its breaking the distance between itself and the player to do the movement code?

I dont know why its going up into the air. and i dont know the answer to you second question

Well nothing in what you’ve posted here should be making the AI go up into the air, so there must be another script in the scene that’s making it move upward

As for the second question, you could easily figure out if its distance related by my earlier post, but you inexplicably chose to ignore it for some reason.

Change you code to this, for some simple debugging:

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) {
                Debug.Log("I am within attack distance.");
		var rotate = Quaternion.LookRotation(Vector3(target.position.x, transform.position.y, target.position.z) - 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) {
		Debug.Log("I am not within attack distance.");
	}
}

Then run the code, and look in the log and see which Debug.Log message is getting printed when the enemy is stuck.

when it stops moving, it says its attacking, so something is wrong, but i dont know what

I dont know what is happening!!!