Enemy Doesn't move with AI script

So when enemy can see player he doesn’t move, I can go close up and he will rotate but not move.

var moveSpeed = 3;//Move Speed
var rotationSpeed = 3;//Rotation Speed

var hit : RaycastHit;
var fieldOfViewRange : float = 68;// Angle the Enemy can see the player
var Player : GameObject;
var Range : float = 10;
var chaseDistance : float = 10;//Distance the Enemy will chase
var giveUpChaseDistance = 16;//Distance the Enemy will give up

private var rayDirection = Vector3.zero;
private var chasing = false;

var LookAt = false;
var myTransform : Transform;
var target : Transform;

function Awake(){
	myTransform = transform; //cache transform data
}
function Update() : boolean{
	
	rayDirection = Player.transform.position - transform.position;
	var distanceToPlayer = Vector3.Distance(transform.position, Player.transform.position);
		
		if((Vector3.Angle(rayDirection, transform.forward)) < fieldOfViewRange){
			if(Physics.Raycast(transform.position, rayDirection, hit, Range)){
				if(hit.transform.tag == "Player"){
					LookAt = true;
					Debug.Log("Can see");
					return true;
					
			}
				else{
					Debug.Log("Can not see");
					return false;			
		
			}
		}	
	}
	
	if(LookAt == true && distanceToPlayer <= chaseDistance){
		chasing = true;	
	}
	if(chasing == true){
		//Rotate to face Player
		myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
        Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
       	//Move to the player
        myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
	}
}
function OnDrawGizmosSelected (){
    Gizmos.color = Color.magenta;
    Gizmos.DrawRay (transform.position, transform.forward * Range);      
}

Thanks :slight_smile:

Got it to work finally.

If anyone is interested please use it:

var moveSpeed : float = 3;
var rotationSpeed : float = 3;

var player : GameObject;
var myTransform : Transform;
var target : Transform;
var fieldOfView : float = 50;
var rayRange : float = 10;

var lookingAt = false;

function Awake(){
	myTransform = transform;
}

function Update(){

	var hit : RaycastHit;
	var rayDirection = player.transform.position - transform.position;
	
	//Checks if can see player
	if((Vector3.Angle(rayDirection, transform.forward)) < fieldOfView){
		if(Physics.Raycast (transform.position, rayDirection, hit, rayRange)){
			if(hit.transform.tag == "Player"){
				Debug.Log("Can see you MF");
				lookingAt = true;
			}
			else{
				Debug.Log("Where are you MF?!?");
				lookingAt = false;
			}
		}
	}
	
	if(lookingAt == true){
		myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
        Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
        
        //move towards player
        myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
	}
}

function OnDrawGizmosSelected(){
	Gizmos.color = Color.green;
	Gizmos.DrawRay (transform.position, transform.forward * rayRange);
}