How can I calculate multiple paths?

Get help using Construct 2

Post » Sat Jul 05, 2014 10:38 am

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

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 :
Image
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?
B
3
Posts: 4
Reputation: 185

Post » Sun Jul 06, 2014 7:24 am

Up
B
3
Posts: 4
Reputation: 185

Post » Sun Jul 06, 2014 1:06 pm

@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?
Find all the Construct 2 games that were on Steam Greenlight here
B
36
S
10
G
7
Posts: 475
Reputation: 7,015

Post » Sun Jul 06, 2014 2:04 pm

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.
B
3
Posts: 4
Reputation: 185

Post » Sun Jul 06, 2014 3:45 pm

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.
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,680

Post » Sun Jul 06, 2014 6:42 pm

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 :)
B
3
Posts: 4
Reputation: 185


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests