Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

How do I make the enemy ai stop following the player in the scene properly on unity3d

$
0
0
I have the enemy ai following the play and I nav mesh set to stop in the inspector . The problem is the enemy ai is still following the player regardless if its dead or alive . I want the enemy ai to die where its at. I have it to where the enemy ai is checking to see if the player is near. Here is my script : using UnityEngine; using System.Collections; public class Enemyai : MonoBehaviour { public Transform player; static Animator anim; public NavMeshAgent nav; void Start () { anim = GetComponent (); } void Update () { if (Vector3.Distance(player.position, this.transform.position) < 13) { Vector3 direction = player.position - this.transform.position; direction.y = 0; this.transform.rotation = Quaternion.Slerp (this.transform.rotation,Quaternion.LookRotation(direction), 0.1f); anim.SetBool("isIdle",false); if(direction.magnitude > 2.6 ) { nav = GetComponent (); nav.SetDestination (player.position); anim.SetBool("isMoving",true); anim.SetBool("isAttack",false); } else { anim.SetBool("isAttack",true); anim.SetBool("isMoving",false); } } else { anim.SetBool("isIdle",true); anim.SetBool("isMoving",false); anim.SetBool("isAttack",false); } } }

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>