hi this is the full code from my last post, please bare with me since im new to this and only started learning about a week ago
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading;
using Pathfinding;
using UnityEngine;
public class enemy_AI : MonoBehaviour
{
public Transform target;
public float speed = 200f;
public float nextWaypointDistance = 3f;
Path Path;
float currentWaypoint = 0f;
bool reachedEndOfPath = false;
Seeker seeker;
Rigidbody2D rb;
void Start()
{
seeker = GetComponent<Seeker>();
rb = GetComponent<Rigidbody2D>();
seeker.StartPath(rb.position, target.position, OnPathComplete);
}
void OnPathComplete(Path p)
{
if (!p.error)
{
Path = p;
currentWaypoint = 0f;
}
}
void FixedUpdate()
{
if (Path == null)
return;
if (currentWaypoint >= Path.vectorPath.Count)
{
reachedEndOfPath = true;
return;
}
else
{
reachedEndOfPath = false;
}
Vector2 direction = ((Vector2)Path.vectorPath[currentWaypoint] - rb.position).normalized;
Vector2 force = direction * speed * Time.deltaTime;
rb.AddForce(force);
float distance = Vector2.Distance(rb.position, Path.vectorPath[currentWaypoint]);
if (distance < nextWaypointDistance)
{
currentWaypoint++;
}
}
}