So I am trying to use A* for my enemy AI but it is not working at all. I successfully made a map and added a seeker to my AI but when I try to generate a path, it seems to completely disregard the un-walkable area. As you can see in my screenshot, the platforms are designated as un-walkable area but when the AI is making a path, it just draws a straight line right through this area. Please advise, what am I doing wrong? Thanks in advance.
Can you post your calling script?? Sadly I cant diagnose much without reading it~
Of course:
I was following the getting started guide. Let me know if you need any more info. Thanks!
`using UnityEngine;
using System.Collections;
using Pathfinding;
public class EnemySeeker : MonoBehaviour {
public Vector3 targetPosition;
private Seeker seeker;
private CharacterController controller;
public Path path;
public float speed = 5;
public float nextWaypointDistance = .1f;
private int currentWaypoint = 0;
public void Start() {
seeker = GetComponent<Seeker>();
controller = GetComponent<CharacterController>();
seeker.pathCallback += OnPathComplete;
seeker.StartPath(transform.position, targetPosition);
}
public void OnDisable(){
seeker.pathCallback -= OnPathComplete;
}
public void OnPathComplete(Path p) {
print("Yay! we got back a path. Did it have an error?" + p.error);
if(!p.error){
path = p;
print (path.vectorPath.Count);
currentWaypoint = 0;
}
}
public void FixedUpdate(){
if(path == null) return;
if(currentWaypoint >= path.vectorPath.Count){
print ("End of path reached!");
return;
}
Vector3 dir = (path.vectorPath[currentWaypoint] - transform.position).normalized;
dir *= speed * Time.fixedDeltaTime;
controller.Move(dir);
if(Vector3.Distance(transform.position, path.vectorPath[currentWaypoint]) < nextWaypointDistance){
currentWaypoint++;
print (currentWaypoint);
return;
}
}
}`
Hi
-
You seem to have rotated the graph 90 degrees. Consider changing the Max Climb value or at least the Max Climb Axis in the grid graph settings.
Right now, all those coloured lines you see are different areas in the graph. Meaning in this case that a unit can travel horizontally (as seen in the image), but not vertically. -
Change Seeker -> Start End Modifier -> End Point to ClosestOnNode instead of Original (or download the beta, if possible, it is the default setting there).