How can I make my script have the enemy look at the Player without using the local Y axis so he doesn’t rotate into the air? So far he looks at the Player but once the Player gets too close or jumps, he’ll start rotating into the air to look at him, any help?
//LOOK AT THE PLAYER ONCE TARGETED//
if(targeted){
var rotation = Quaternion.LookRotation(Player.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
ChasePlayer = gameObject.GetComponent("EnemyControl");
if(distanceToTarget >= 2){
isMoving = true;
}else{
isMoving = false;
}
}else{
isMoving = false;
}
//CHASE THE PLAYER//
if(isMoving){
animation.CrossFade("run",0.2);
var controller2 : CharacterController = GetComponent(CharacterController);
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
controller2.SimpleMove(forward * 3);
}
}