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);
}