So im trying to make an enemy AI that when im close to him enough it will rotate and then follow me, the rotation is working but he is not following me.
Here is the code:
void Update () {
if (Vector3.Distance (player.position, this.transform.position) < 10) {
Vector3 direction = player.position - this.transform.position;
direction.y = 0;
this.transform.rotation = Quaternion.Slerp (this.transform.rotation, Quaternion.LookRotation (direction), speed * Time.deltaTime);
anim.SetBool ("is_idle", false);
if (direction.magnitude > 5) {
this.transform.Translate (0, 0, 0.05f);
anim.SetBool ("is_running", true);
anim.SetBool ("is_attacking", false);
} else {
anim.SetBool ("is_attacking", true);
anim.SetBool ("is_running", false);
}
} else {
anim.SetBool ("is_idle", true);
anim.SetBool ("is_running", false);
anim.SetBool ("is_attacking", false);
}
}