title: A* pathfinding AI object moves towards a moving target Unity
body: <p>I am trying to make an AI object to chase my player. The player is controlled by the user. </p>
  
  <p>This is the code that I have so far for the AI when the target is in a fixed position not moving. How can I change it to make my AI object chase my player?</p>
  
  <pre><code>public class AstarAI : MonoBehaviour
  {
  
      //The point to move to
      public Transform target;
  
      private Seeker seeker;
  
      //The calculated path
      public Path path;
  
      //The AI's speed per second
      public float speed = 2;
  
      //The max distance from the AI to a waypoint for it to continue to the next waypoint
      public float nextWaypointDistance = 3;
  
      //The waypoint we are currently moving towards
      public int currentWaypoint = 0;
  
  
      public bool arrived;
  
      public void Start()
      {
         seeker = GetComponent&lt;Seeker&gt;();
         arrived = false;    
         seeker.StartPath(transform.position, target.position, OnPathComplete);
  
      }
  
  
  
      public void OnPathComplete(Path p)
      {
          Debug.Log("Path calculated? " + p.error);
          if (!p.error)
          {
              path = p;
              //Reset the waypoint counter
              currentWaypoint = 0;
          }
      }
  
      public void FixedUpdate()
      {
  
  
          if (path == null)
          {
              //We have no path to move after yet
              return;
          }
  
          if (currentWaypoint &gt;= path.vectorPath.Count)
          {
              Debug.Log("End Of Path Reached");
              arrived = true;
              return;
          }
  
          //Direction to the next waypoint
          Vector3 dir = (path.vectorPath[currentWaypoint] - transform.position).normalized;
          dir *= speed * Time.fixedDeltaTime;
          this.gameObject.transform.Translate(dir);
  
          //Check if we are close enough to the next waypoint
  
          if (Vector3.Distance(transform.position, path.vectorPath[currentWaypoint]) &lt; nextWaypointDistance)
          {
              currentWaypoint++;
              return;
          }
      }
  }
  </code></pre>