I have a scene that is based on the example. I just have capsule with the seeker script, an AITester script (code provided below) and i have layers for obstacles and ground. I have my a star object with the pathfinder script and am doing a grid graph. The graph scans fine and shows unwalkable areas, but then when i run the scene, my seeker seems to walk on these and get stuck trying to go through a wall.
The attached images show my AI settings and my scene layout with my ai graph that is generated. The green line is the path generated, and my ai (the capsule) just moves on the line, but then “rubs” up against the wall until it slides sideways enough to follow the path closer, then it rubs the path again when it is closer to the goal and has to round a corner. My ai is crossing nodes that are marked as unwalkable and i am confused why. There aren’t even any nodes here.
oh whoops, i forgot to include my code:
here is its:
The variables and gameobjects are being found, so no null references, and i have made my script variables private and public again (to avoid inspector overriding values).
using UnityEngine;
using System.Collections;
using Pathfinding;
public class testAStar : MonoBehaviour
{
//The point to move to
public Vector3 targetPosition;
public Vector3 targetDefaultPos = new Vector3(0,0,0);
public GameObject targetObj;
public Seeker seeker;
public 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 void Awake()
{
targetObj = (GameObject)GameObject.Find("target");
}
public void Start()
{
//Get a reference to the Seeker component we added earlier
seeker = GetComponent<Seeker>();
controller = GetComponent<CharacterController>();
if(targetDefaultPos.Equals(Vector3.zero) )
{
targetPosition = targetObj.transform.position;
}
else
{
targetPosition = targetDefaultPos;
}
//Start a new path to the targetPosition, return the result to the OnPathComplete function
seeker.StartPath(transform.position,targetPosition, OnPathComplete);
}
public void OnPathComplete(Path p)
{
Debug.Log ("Yey, we got a path back. Did it have an error? "+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 >= path.vectorPath.Length)
{
Debug.Log ("End Of Path Reached");
return;
}
//Direction to the next waypoint
Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;
dir *= speed * Time.fixedDeltaTime;
controller.SimpleMove(dir);
//Check if we are close enough to the next waypoint
//If we are, proceed to follow the next waypoint
if (Vector3.Distance(transform.position,path.vectorPath[currentWaypoint] ) < nextWaypointDistance )
{
currentWaypoint++;
return;
}
}
public void Update()
{
}
}
I created another scene with the same setup (an a*star object, a seeker script and obstacles and ground labels. The only thing different is in the script for testing the ai, i changed:
public float nextWaypointDistance = 3;
to
public float nextWaypointDistance = 0.5f;
As of current my AI seems to not follow the grid nodes and runs straight into the wall. In the below images the first shows my scene and my start and goal obstacles.
In the second image, i show the game path and where my ai gets stuck (the highlighted capsule object).
Again, my path that is calculated and my ai should follow is highlighted in green.
I also have a problem with my ai pausing for a very long time before moving. It tells me in the terminal debugger that the path took 60ms to calculate, but then my ai doesnt start moving till a minute later. If i hit play and let it calculate the path and then stop the editor preview, and then play again, my ai moves instantly, showing that it took 60ms again to calculate the path. Why could this be?
I do have an idea of why it runs into the wall. But first i need to know how do you trace back the path? You find the end node and then trace its parents? Dont know why the second thing occur.
I did not trace the path, by following nodes or with some extra script, i just ran my scene in the editor and while it was running i viewed it in scene view (not game view or it wont show up). The framework generates this green highlighted path at runtime for the scene view only. I assume this path is correct as it is part of the framework and not my own code.
And what could cause these? And how could i try and debug them?
The ai follows a curve and then doesnt go far enough above the wall and it “slides” back down towards the goal along the wall. Here’s three images to show where the ai gets stuck on the wall and starts to slide down:
I have the exact same problem. Any help would be appreciated since I have no idea how to fix it. The green line which is supposed to be the calculated route is drawn correctly, but the object just isn’t following it.
I was having a similar problem. I was using a terrain, not a plane. The seeker was walking straight into unwalkable nodes. Upon inspection, the Path.vector array only had two nodes, the start point and the finish point. Root cause: the max climb value was set to 0.1 (default, maybe? Or maybe I put it in, no clue), which broke up the nav grid into many small areas, with no indication of that showing in the editor. Setting the max climb to 10 or something and pressing “scan” solved the issue for me.
The max climb thing is not a bug by itself, but it’s a pretty big deal that you don’t see the exclusive areas in the editor. What is a bug is the seeker going through unwalkables when this happens (doesn’t always happen, sometimes the proper error is returned).
I’m guessing this thread is long dead and the problem has been solved however I came accross this as my seeker was exhibiting the same issues. I resolved it by changing the Seekers ‘Traversable Graphs’ to only my graph rather than the default which is all.