using System; using System.Collections; using System.Collections.Generic; using Pathfinding; using UnityEngine; public class AStarTest : MonoBehaviour { public Transform target; public Seeker seeker; private CharacterController controller; //The calculated path public Path path; //The AI's speed per second public float speed = 100; //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 private int currentWaypoint = 0; public AIPath aiPath; [Obsolete("Obsolete")] private void Start() { seeker.StartPath(transform.position, target.position,OnPathComplete); aiPath.SetPath(path); } public void OnPathComplete(Path p) { if(p.error) return; path = p; currentWaypoint = 0; } private void FixedUpdate() { // if(path == null) // return; // if(currentWaypoint>=path.vectorPath.Count) // return; // Vector3 dir=(path.vectorPath[currentWaypoint]-transform.position).normalized; // dir *= speed * Time.fixedDeltaTime; // controller.SimpleMove(dir); // if (Vector3.Distance(transform.position, target.position) < nextWaypointDistance) // { // currentWaypoint++; // } } }