Stop enemy from chasing at a certain point
Hi, I have an enemy ai script. Now I want add, that the enemy stops at a certain point what do i have to add?`using System.Collections; using System.Collections.Generic; using UnityEngine;
public class enemyController : MonoBehaviour {
public Transform player;
public float playerDistance;
public float awareAI = 10f;
public float AIMoveSpeed;
public float damping = 6.0f;
public Transform[] navPoint;
public UnityEngine.AI.NavMeshAgent agent;
public int destPoint = 0;
public Transform goal;
public static float enemyHealth;
void Start () {
UnityEngine.AI.NavMeshAgent agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
agent.destination = goal.position;
agent.autoBraking = true;
}
void Update () {
playerDistance = Vector3.Distance (player.position, transform.position);
if (playerDistance < awareAI)
{
LookAtPlayer();
}
if (playerDistance < awareAI)
{
if (playerDistance < 10f)
{
agent.SetDestination(player.transform.position);
}
else
GotoNextPoint();
}
if (playerDistance > 5f)
{
}
if (agent.remainingDistance < 0.5f)
GotoNextPoint();
}
void LookAtPlayer()
{
transform.LookAt(player);
}
void GotoNextPoint()
{
if (navPoint.Length == 0)
return;
agent.destination = navPoint[destPoint].position;
destPoint = (destPoint + 1) % navPoint.Length;
}
void Chase ()
{
transform.Translate (Vector3.forward * AIMoveSpeed * Time.deltaTime);
}
}
`
Comment
Your answer
Follow this Question
Related Questions
Boss ai help EoW 0 Answers
How to have multiple enemies (currently having to kill them in order) 1 Answer
Random Number keeps generating over and over 2 Answers
Enemy animation gets weird when going to set position 0 Answers
I want to stop movement of character while i call animation like Kick Jump Punch etc.. Please help 1 Answer