can anyone help me , how to fix this , somehow my monster ai only move forward after player come near them. thank you.
using System.Collections;
using UnityEngine;
public class chase : MonoBehaviour
{
public Transform player;
static Animator anim;
void Start()
{
anim = GetComponentInChildren<Animator>();
}
void Update()
{
if (Vector3.Distance(player.position, this.transform.position) < 10)
{
Vector3 direction = player.position - this.transform.position;
direction.y = 0f;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
Quaternion.LookRotation(direction), .1f * Time.deltaTime);
anim.SetBool("Idle", false);
if (direction.magnitude > 5)
{
this.transform.Translate(0, 0, 0.05f);
anim.SetBool("Walking", true);
anim.SetBool("Attacking", false);
}
else
{
anim.SetBool("Attacking", true);
anim.SetBool("Walking", false);
}
}
else
{
anim.SetBool("Idle", true);
anim.SetBool("Walking", false);
anim.SetBool("Attacking", false);
}
}
}