- Home /
how do i make enemy ai chase player
this is my code. it works but the enemy ai behaviour is weird and the hitbox is gone, i'm a beginner and this is not my code private Transform target; public int MoveSpeed = 4; public int minRange; public bool follow; public float scoreOnDeath; private Player player;
void Start(){
player = GameObject.FindGameObjectWithTag ("Player").GetComponent<Player> ();
GameObject go = GameObject.FindGameObjectWithTag ("Player");
target = go.transform;
}
public override void Die() {
player.AddScore (scoreOnDeath);
base.Die ();
}
void Update ()
{
if(Vector3.Distance(transform.position,target.position)<minRange)
follow=true;
if(follow){
transform.LookAt(target);
transform.Translate(Vector3.forward * Time.deltaTime);}
}
}
Clarify the problem at hand. What do you mean by " enemy ai behaviour is weird"? What do you mean by "the hitbox is gone"? Be precise and to the point, people can't help you if you don't provide enough information. Also, please fix the code formatting. The first couple of lines are not formatted as code.
Your answer
Follow this Question
Related Questions
Simple AI Error 8025 Parrsing error. 2 Answers
How to make a Raycast enemy? 0 Answers
Animation not following character? 0 Answers
get enemy to chase and shoot at player wherever hes facing. 0 Answers
Enemy ia fliping when hitting object 2 Answers