Hello,
I have a problem with pathfinding. As shown in the image, there is a Player (P) and three Enemies (E). The player can be controlled with mouse clicks or the keyboard. After reaching any position, you need to press "End Turn." Then, the enemies move one after another. They should move toward the player and stop on an adjacent tile. This works well so far.
However, it can happen that a preceding enemy blocks the path. In that case, the following enemies should move as close to the player as possible. I solved this by creating a new dummy sprite (failDummySprite) at the position of the last enemy, which then serves as a new target.
Now, here’s the problem. Sometimes it works perfectly, for example, in the hallway at the beginning. However, sometimes the last enemy cannot find a path, even though there should be one. See the fields marked as "Fail" in the image. Additionally, on the field marked as "Test," you can see that the last enemy takes a non-optimal path. In my opinion, this is the root of the problem: when the path is "blocked," they cannot reach the target. I just can't figure out the issue. Why doesn't it always find the optimal path? I regenerate the path map for each new enemy, but sometimes it fails to find a path to the target. I'm slowly getting desperate.
Does anyone have an idea?
Thanks!
https://drive.google.com/file/d/1G9IdE8UfHh2lFsqwTPJTv5Yvba3aHq7C/view?usp=drive_link