Pathfinding being a pain.

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Im using the Pathfinding behaviour for my enemies in my tower defence game.

    The code is set up like this:

    My levels look like this:

    Behaviour settings look like this:

    These levels did work, but then the next time I ran the game, they refused to move.

  • First, if you post your project you will get better help because the problem could be something not intuatively related to the code or path tiles.

    For example, if your sprites collision bounds expand into the solid portions of the walls when it spawns, the pathfinding algorithm might have trouble finding a valid path. Or, if the bounding box can't fit around a specific bend, the pathfinding can struggle. Also, depending on the settings in the pathfinding behavior, the path might not be what you think it is. Differences between your cell size setting and your actual wall size can make the actual path smaller than you think.

    If the paths worked previously and are broken now, you most likely changed one of the above settings.

    You show your cell size as 20. Your tile size appears to be 32X32 but that is a guess from looking at the image. For a cell size of 20 to completely cover a tile size of 32X32, the cell would have to be 40 (or a 2X2 cell) completely cutting into the path. I would guess this is the problem but without actually having the project in hand, it is only a guess.

    Try changing the cell size to 32 and see what that does.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi,

    No settings had been changed between when it worked and when it didn't. I did try a cell size of 32, but it unfortunately did nothing.

    I have attached my project file. My hope is im missing something simple.

    https://www.mediafire.com/file/ckor37xhvn156xx/ConstructForumHelp.c3p/file

    Thanks for the help.

  • Hi!

    You uploaded the file with the error, which helped speed up the process.

    I took a few screenshots to explain my point.

    First, I removed all the extra bee objects and left just one; this lets us change its settings, and whenever it spawns somewhere, those settings will always be the same.

    I changed one parameter on the bee, and it flew away.

    But I don’t like your spawn function—it’s a total clunker. Any looping function should happen instantly in a single frame; the fact that you added a delay simply interrupts it and restarts it. This isn’t standard practice—it’s a workaround that’s been around since Construct 2.

    But we need a reliable solution, and we shouldn’t use any delays in the looping action.

    I created a new function, and as you can see, during spawning, we configure the bee and start a timer.

    Then, when each bee’s timer expires, it will find its path and start moving.

    This is just one of the possible ways to spawn a wave of mobs.

    Download the project file

    fex.net/s/0ex1myf

  • That has fixed it. I did originally have the Cell Border as -1, I must have changed it without thinking at some point. Removing the ones in the other layouts has also helped.

    Thanks for the code improvements; that is a much better way of doing it.

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