Pathfinding Problem - sometimes no path

0 favourites
  • 3 posts
From the Asset Store
For problem solving, puzzles, bubbles, platforms and other adventures.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It can't find a path to the dummy because it is on top of an obstacle the solid enemy. Also ths way you developed this game is kind of a performance no no in finding path every tick.

  • Ah, of course. Thank you! I missed that.

    The way the auto-movement with pathfinding and tile movement is implemented is based on two examples from this forum. I couldn't figure out another way to do it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)