Pathfinding issues when layout is accessed through game, not previewing layout.

0 favourites
  • 12 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi folks! I've had great luck posting here before about weird issues (most end up being human error, ofc lol) - so let's give this one a whirl: I am attempting to get permission from my partner, to post my .c3p file here, as there are a lot of finished assets in there already... but in the mean-time I will try to be as descriptive as possible. (apologies ahead of time, I am having a weird brain day and am also really new to Construct, so my terminology might not be 100% proper xD)

    I am creating an RTS/open world/TD game where you place towers and units spawn out of them, path to the enemy's castle and attack enemy units/towers along the way while avoiding your own towers. You are only able to build in the first ~thousand pixels on "your side".

    The pathfinding is working PERFECTLY when I load up the level layout itself for testing.

    But if you were to play the actual game, you start on a <Main Menu> layout then click start to go to your <Empire> (think Heroes of Might and Magic castle scene). From there you can select a map to play, which will take you to the <level> layout.

    The first time played, a brief tutorial will play (which doesn't trigger for some reason when I'm testing the level layout on its own... only when I go in through the main menu... so that could be part of the issue/it seems to connect) and then the player can place towers - this also triggers the AI to build towers, which doesn't happen when I'm launching the level layout alone.

    TL/DR? My pathfinding units work perfectly (avoid the custom obstacles while moving along path) when the <Level> layout is launched by itself. But when launching my game from the <main menu>, as intended for the real game, other events seem to be confusing/preventing this pathfinding behaviour from working the same way.

    If this is a rookie mistake - something easy that I'm not considering - and I don't need to share my c3p file, that would be preferrable... but let me know if a hands-on view is needed to understand the issue.

    Thanks in advance for any help :D

  • Hi folks!

    D: I may have posted this in the wrong forum section...

  • If you add new obstacles you have to regenerate the obstacle map.

    The grid of obstacles is only determined once on startup. If objects are moved in the layout, the pathfinding grid is not updated, and objects will continue to pathfind as if the objects were in their old positions. To update the entire obstacle grid use the Regenerate obstacle map action, but note this is a very CPU-intense operation and should only be done on one-off occasions. It is much more efficient to update only small parts of it (ideally only the area that has changed), which can be done with the Regenerate region and Regenerate region around object actions.

  • savvito123 thank you very much for your reply; right now I have an "on created" even for the units which will regenerate their obstacles when they are created... I actually ended up putting "clear all obstacles", then readd the towers, then it worked - but only when I load the Level Layout that I'm testing. It still does not work when I go to that layout from other layouts in the game -_-

  • I now have permission from the artist to post the construct files; if anyone thinks they can help, but needed to look at the c3p file first....... let me know.

  • Please share.

  • I think this should work; I've never shared my projects on here before D:

    https://drive.google.com/file/d/1kzIP3y9yv2P0kiuAZ_ue4ptUqomXUh7N/view?usp=sharing

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Also, I apologize ahead of time if my project is a little confusing/noobie lol; I am self taught in Construct and just starting to learn C# with Unity, meaning I may not have things ordered/sorted "properly"

  • Hello ,

    It seems this fix your issue

    I dont know why but the last 4 hours i was searching for the problem using the disable method (remove events until the issue gone) i thing this was the problem.

    Maybe another guy can tell us why other sprites pathfinder behavior mess other sprites pathfinder behavior.

    Also you cannot set as custom obstacles same sprites, you have to add them as family and then add the family as custom obstacle.

    Using families you can reduce your code in lot of events.

    And it seems that effects cause extremely high CPU usage so its better to avoid it.

    Ah , you can use subevents

    use this

  • Thank you for that help savvito123 !! I knew something wonky was going on there with the pathfinding obstacles - the thing is, I don't want the blue/player units to avoid the red/ai towers (I should stop switching back and forth between that terminology in my events too.. unnecessarily confusing.) - the units are supposed to attack the opposing towers, and avoid their own towers.

    I really appreciate the tip on using families and sub events in the creation event, though! I will implement those changes right now :D

    Yeah... I was thinking the effects were going to cause a high CPU usage... and probably adding to the problem is I was using "regenerate obstacle map" instead of "regenerate region" or "region around object", which I was just doing some more reading on. I do want to have some nice flashy(or in my case, wavy) effects though, so perhaps I could just reduce CPU usage elsewhere?

    -Dumb question possibly, but does reducing the rate of the effect or manipulating its opacity/etc, reduce its CPU usage or is it just a flat usage rate once enabled?

  • Thank you for that help savvito123 !! I knew something wonky was going on there with the pathfinding obstacles - the thing is, I don't want the blue/player units to avoid the red/ai towers (I should stop switching back and forth between that terminology in my events too.. unnecessarily confusing.) - the units are supposed to attack the opposing towers, and avoid their own towers.

    It seems they can attack the towers even if they are in pathfinder to avoid them.

    I did not found any other way to avoid only their own towers.

    -Dumb question possibly, but does reducing the rate of the effect or manipulating its opacity/etc, reduce its CPU usage or is it just a flat usage rate once enabled?

    Its only when the effect is run, but it seems that the game crash when the effect is running and click some times.

    Btw nice game.

  • It seems they can attack the towers even if they are in pathfinder to avoid them.

    Very odd, but that's wonderful! I am just making burgers then I'll be messing around with this some more :D I will let you know if I run into any more problems!

    Again, I really appreciate the help

    Btw nice game.

    ^-^ HUGE thank you, hopefully I can FINISH it lol.. which is not one of my strong points.

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