valantonini/AStar

Entity blocking itself

Lurler opened this issue · 3 comments

Hey!

There's a small issue with using the library. I'm not sure how to elegantly solve it without some hacks...

I have a grid (WorldGrid) which stores not just terrain data (e.g. which tiles are walkable/blocked) but also takes into account all entities on the map and block those cells as well, so entities don't walk to top of each other. I think this is pretty normal implementation for most games.

But here's the problem. Since the entity is actually standing in the cell it can't build a patch because the cell it is standing in is also considered blocked... I can obviously add some hacks where the entity first marks the cell it is standing on and the target cell as walkable, but it isn't exactly a good way to address it.

Maybe you can just add two simple options along the lines of:

private static readonly PathFinderOptions PathfinderOptions = new()
{
    IgnoreStartCellBlock = true,
    IgnoreEndCellBlock = true,
};

Or something of this nature. Basically so that:

  1. Entities don't block itself from moving by the virtue of existing in the cell.
  2. and can still build a path to another cell even if that cell is occupied by an entity (e.g. when monster builds a path to the player cell, even though this cell is blocked by the player).

Obviously if there's a better solution that I have missed please let me know :)

Hi @Lurler,

Interesting, are you able to provide an example? Is the issue that the algorithm can't start on a square that's classed as obstructed?

thanks,

val

Thank you for quick reply!

Yes, if you try to start the search from a cell that's marked as blocked it cannot build a path anywhere (and returns an empty result as expected), same goes for trying to build a path to a cell that's blocked.

That is understandable why it can't do it in both cases, as technically those cells are blocked. Still, I think it is very useful to be able to disregard the blocked status of start and end points of the search precisely because they can be blocked by entities that are doing the search.

I also have this issue. I have castles on a map, that are obstructions, that I want to find paths between, but without modification no paths can be found.