Weird pathfinding in 2d game

So I have everything setup for a 2d game with this amazing pathfinding, right? Well I don’t have local avoidance because I’m poor =(
Anyway: my character sprites are on a layer that the gridgraph casts as unwalkable. So at the start the characters in this grid/tile based game are obstacles and the path finding moves around them. Awesome. Well when they move the graph doesn’t update and now they’re ghost! walk right through them!
Oh well I make a call to rescan
( GameObject.Find(“Astar”).GetComponent().Scan(); ) (might be a bit of a hack)
and then WHEEE the characters are unwalkable again!
So that’s awesome. It’s a turn based game so it’s okay so far.

Well the weird thing is when a character is on an unwalkable node it always “Exits” to the left (to get onto a path again (i see that i’m not on the grid when i’m on that unwalkable node).
Why is it that the left node is calculated as the nearest and is there a way to fix this?

Thanks!
-Xellinus Demitris Ruin

Hi

The pathfinder needs to find the nearest node, if there are multiple with the same distance it has to favor something since otherwise it would in practice have to to multiple pathfinding searches. So it favors going to the left.

What you could do is something like this:

  1. Basic state, all sprite nodes are unwalkable
  2. Upon getting a pathfinding request for a sprite:
  3. Make the node under the sprite walkable using GraphUpdateObjects
  4. Start pathfinding request (seeker.StartPath or something).
  5. Make sure the pathfinding request is calculated immediately (AstarPath.WaitForPath(myPathObject))
  6. Move the sprite (I assume your game does this here)
  7. Make the new sprite node unwalkable.

//Note: You can get the path object from the StartPath function Path p = seeker.StartPath(...) AstarPath.WaitForPath(p);

Cheers,
Aron

Thank!