Updating Seeker path after graph update

HomeForumsA* Pathfinding ProjectBeginner QuestionsUpdating Seeker path after graph update

This topic has 2 voices, contains 3 replies, and was last updated by  Aron Granberg 102 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
Author Posts
Author Posts
January 30, 2012 at 09:40 #1383

Brad

Hi, I’m using this to build a Tower Defence game. So far I’m able to update the graph when I place towers (see code below) but the Seeker agent doesn’t re-calc its path (and hence runs into the new towers).

Each tower prefab has the following C# code attached; this works and updates the graph with new red blocks seen in the editor (although if I include either of the commented-out settings for the GUO the update doesn’t work).

void Start ()
{
Collider col;
col = collider;
Bounds newBounds = col.bounds;

GraphUpdateObject guo = new GraphUpdateObject (newBounds);
//guo.updatePhysics = true;
//guo.modifyWalkability = true;
guo.setWalkability = true;

AstarPath.active.UpdateGraphs (guo);
}

Is there an extra line of code I need to add here or on the seekers to make sure they update their paths after a graph update?

Thanks in advance!

February 6, 2012 at 09:53 #1428

Hasan Bozok

You build the tower over a walkable path i think, i am not sure but i think you should use the collider of path which is under your tower.What i want to say is, if you are placing towers over a slot which has an collider for path calculation, you should use that slots collider’s bounds.

February 6, 2012 at 13:44 #1433

Aron Granberg

There is a callback named OnGraphsUpdated which you can register to. Then you can have a function be called every time the graphs are updated (to for example recalculate the paths).

public void OnEnable () {
//Register to the callback
AstarPath.OnGraphsUpdated += MyUpdateFunction;
}
public void OnDisable () {
//To prevent it from receiving callbacks when the object has been destroyed
AstarPath.OnGraphsUpdated -= MyUpdateFunction;
}
public void MyUpdateFunction (AstarPath active) {
//Recalculate the path
}

February 6, 2012 at 13:46 #1434

Aron Granberg

Okay, that’s weird… It should work if you only set “updatePhysics = true”, though this is practically what you are doing since that’s the default value.
If you are using version 3.0.6 (I think), you might want to upgrade, that version had a bug related to graph updates.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Updating Seeker path after graph update
Your information:






<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>