Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity blocking itself #11

Open
Lurler opened this issue Feb 10, 2023 · 3 comments
Open

Entity blocking itself #11

Lurler opened this issue Feb 10, 2023 · 3 comments

Comments

@Lurler
Copy link

Lurler commented Feb 10, 2023

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 :)

@valantonini
Copy link
Owner

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

@Lurler
Copy link
Author

Lurler commented Feb 20, 2023

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.

@tfritzy
Copy link

tfritzy commented Jun 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants