AI Controller

Hi there the question I have is with the script below. My game is in 2.5D and when I jump over the enemy he like turns around in a full circle disappearing into the floor and also in the air. I only want him to rotate in the Y Axiz. I will show you some pics Below Please help guys.

Here is the Code i am using

    function Awake()
{
animation["Walk"].layer =0;

}

var waypoint : Transform[];
var speed : float = 20;
private var currentWaypoint : int;
var loop : boolean = true;
var player : Transform;

function Update() {
		
	var distFromPlayer : Vector3 = player.position - transform.position;
	if(currentWaypoint < waypoint.length){
	
		
		var target : Vector3 = waypoint[currentWaypoint].position;
		var moveDirection : Vector3 = target - transform.position;
	
		var velocity = rigidbody.velocity;
		if(moveDirection.magnitude <1){
			currentWaypoint++;
		}
		else if (distFromPlayer.magnitude < 10){ // If we are close to the enemy
	
		animation["Walk"].wrapMode = WrapMode.Loop;
	
	
				
		velocity = Vector3.zero;
		target = player.position;
		velocity = (player.position - transform.position).normalized * speed;
		if((player.position - waypoint[currentWaypoint].position).magnitude > 50){
		target = waypoint[currentWaypoint].position;
		velocity = moveDirection.normalized * speed;
		
		animation.Play("Walk");
		
		}
	}
		else{
			velocity = moveDirection.normalized * speed;
			}
	}
	else{
		if(loop){
			currentWaypoint = 0;
		
		}
		else{
			velocity = Vector3.zero;
		}
		
	}
	
		rigidbody.velocity =velocity;
		transform.LookAt(target);
	
}

alt text

ok got it.

You can use something like this to get a lookat effect with only one axsis

var targetPosition : GameObject;

function Update(){

var targetPoint = targetPosition.transform.position;
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position, Vector.up);
transform.position.y = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime*2.0).y;
}

let me know if that worked for you. If not you might want to consider to have your visible enemy independent of your enemy’s controlling transform.