How can I calculate multiple paths?

0 favourites
  • 6 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • Hello, I'm new to Construct 2.

    I chose to start out building a tower defense like game.

    I would like to be able to have 2 different end point for my critters.

    This means they have to choose between 2 different destination.

    The problem is that, according to construct 2's documentation

    [quote:2tzpcnnt]Find path

    Start calculating a path to a destination in the layout. This is processed in the background and the results are not immediately ready after this action; you must wait until the On path found or On failed to find path triggers run before the result is known or the path can be moved along. If this action is used while Is calculating path is true, the old path is still calculated and the result triggered, but it then immediately begins calculating the new path and will also trigger for that result.

    Wich means Enemy.onPathFound should be triggered twice if I had two different "EnemyTarget", right? The thing is it only is triggered once.

    Here is an exemple :

    Variable1 ends up at 1.

    Variable2 ends up at 2.

    Am I doing something wrong or is the documentation not up to date on this part? Is there a way around this problem?

  • Up

  • Zelarith

    Maybe because Find path is called twice in the same event for the same object, it only does the most recent one and ignores the other. If they were in separate events the variables would probably end up how you expect.

    But why calculate two paths anyway? Why not pick a destination first and then just calculate the path to that?

  • I can't pick a destination first as I don't know which one of the two destinations is the closest one to me, and, obviously, using the destination's X and Y won't help : I could have a destination 3 px away from me, if I can't reach it without entering a 1000px maze, I would rather go to a destination 100px away from me without walls between us).

    That's why I have to find both of the paths to be able to calculate their costs and then compare the paths length to decide wich one is better.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Seems it's only on the first tick that it doesn't calculate all the paths. If you add a little delay it works.

    I think pathfinding can have some anomalies when run at start of layout - like it can take 1 tick to update the obstacle map when changing layouts.

  • Oh, yeah, I should have thought of this as a viable solution.

    But still, it's weird that the documentation stated that multiple pathfind can be run in the background !

    Anyway, thanks for your answers, this should do the trick

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