How do I code transform translate in unity3d/ Not working right
I had a problem with the enemy ai staying on the player . I did some testing and I found out that the transform translate the problem I am having when the enemy ai moves toward the player . The can't seem to get away from the enemy ai . I have change the numbers on the script to see if it would make a difference in the scene and it did . The problem was the enemy ai attack was off. The enemy ai start attack before the player got near . I just need to fix the transform translate problem . The number I have now is perfect but the enemy ai the player can't get away from the enemy ai.
 using UnityEngine;
  using System.Collections;
  
   public class Enemyai : MonoBehaviour {
   public Transform Player;
   Animator anim;
   public NavMeshAgent nav;
       void Start () 
       {
               anim = GetComponent<Animator> ();
       }
       
       public void Stop(){
       anim.SetBool("isMoving", false);
       anim.SetBool("isAttack", false);
       anim.SetBool("isIdle", true);
       this.enabled = false;
       //Or if you want to destroy the AI script completely
       //Destroy(this)
   }
  
 
   
       void Update () 
       {
          
         float speed = 0.9f;
       if (Vector3.Distance(Player.position, this.transform.position) < 10000f)
           {
               nav = GetComponent <NavMeshAgent> ();
               nav.SetDestination (Player.position);
               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 )
               {
 
 
                   this.transform.Translate(0,0,0.15f);
                   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);
              
          }
       
  }
 
       
  }
 
       
   
   
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                