Hey Aron, first and foremost i’m terribly sorry for misspelling your name all this time, I just realized it has only one “a”.
Ok, I’m trying to implement a ConstantPath and having couple of problems.
First, there’s a bit of confusion regarding the seeker.pathCallback. I registered my own method to it (OnPathComplete) so that I could use that with ConstantPath (as it is explained in documentation). I’d like the callback to happen when I call seeker.StartPath method specifying a callback. It seems it’s being called on any path calculation, regardless whether specified or not. In my current code, I use richAIScript.UpdatePath() method to move the A.I. around when they’re idle. That method uses seeker.StartPath(tr.position, target.position). There’s no callback specified but it calls OnPathComplete anyway. I have two questions regarding this problem:
- Should I stop using UpdatePath and move my A.I. somehow else?
- Is there a way to use the callback on specific paths only (in my case, I need it for ConstantPath but not for other cases)
Second, below is the code with which I’m trying to use the ConstantPath, i.e. get the nodes around it, pick several random ones, see which one is the furthest from player, and start moving towards that (i want to use that for fleeing behavior for now).
void Flee() //this one's being called every tick if player is close enough
{
if (readyToFlee)
{
ConstantPath cpath = ConstantPath.Construct(transform.position, 1000, null);
seeker.StartPath(cpath, OnPathComplete);
readyToFlee = false;
}
}
then when seeker.StartPath(cpath, OnPathComplete) finishes its path calculation, I want to call GetEscapePath.
public override void OnPathComplete(Path p)
{
base.OnPathComplete(p);
GetEscapePath(p);
}
Then get escape path is supposed to get some nodes (in this case 10), choose the farthest one from the player, and start moving towards it.
void GetEscapePath(Path p)
{
ConstantPath cpath = p as ConstantPath; //the problem seems to be here
List<GraphNode> nodeList = cpath.allNodes;
List<Vector3> pointList = PathUtilities.GetPointsOnNodes(nodeList, 10, 10);
Vector3 farthestPoint = GameManager.instance.player.transform.position;
for (int i = 0; i < pointList.Count; i++)
{
if (Vector3.Distance(pointList[i], GameManager.instance.player.transform.position) > Vector3.Distance(farthestPoint, GameManager.instance.player.transform.position))
farthestPoint = pointList[i];
}
seeker.StartPath(transform.position, farthestPoint);
if (MovedSinceLastFrame(GameManager.instance.player.transform.position))
readyToFlee = true;
}
my cpath casting seems to be the problem since it’s throwing a null reference exception (my cpath is null), and i’m not sure how else to cast it. I tried also (ConstantPath)p but it didn’t work.
Also what is ConstantPath exactly. I thought “path” is a collection of nodes in a certain order so it can be traversible. ConstantPath finds all the nodes around a position within a given distance, meaning it’s just a list of nodes without any clear path to follow?
In case I don’t need overlaps is the initial build time the only thing that grid graph is better with? I’m not doing much building but an explosive barrel for example may be a reason to recalculate that part of the graph. I thought recast graph is faster in general.