Recalculate paths when obstacle maps regenerate?

Get help using Construct 2

Post » Thu Nov 07, 2013 3:51 pm

Hi guys
I'm making a RTS like game and as any such game I plan to have units walking here and there. The problem is when I place another building, and regenerate obstacle maps, those units that are on their way needs to recalculate the path based on the new grid, right? But i don't have a clue where they are going... Is there a way to learn their destination so i can recalculate the path? I hope i will not have to store the coordinates in variable or something...
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Thu Nov 07, 2013 4:14 pm

You would store the X and Y at the time they decide where they are going to go in a instance variable on the object. Like when you mouse click somewhere, or if they are set to goto "the mine" or wherever.

Then after recalculating the path, you would use

Find Path To (previous destination)

to reroute them to the same location again.

I think that regenerate path keeps their previous destination in tact though when you run it. i could be wrong.

B
82
S
39
G
15
Posts: 982
Reputation: 16,712

Post » Fri Nov 08, 2013 9:21 am

Yeah, that was my first thought too, storing coordinates. I was hoping, there was a better solution tho. As i see it, a Recalculate Path action for the pathfinder behavior would be a nice addition.
I believe there should be a way to determine where is the last node of a path, giving you the destination coordinates.
B
12
S
3
G
1
Posts: 120
Reputation: 1,829

Post » Fri Nov 08, 2013 11:16 am

[QUOTE=Pakost] Yeah, that was my first thought too, storing coordinates. I was hoping, there was a better solution tho. As i see it, a Recalculate Path action for the pathfinder behavior would be a nice addition.
I believe there should be a way to determine where is the last node of a path, giving you the destination coordinates.[/QUOTE]

https://www.dropbox.com/s/2m455kl05q7g0w2/Pathfinding.capx

You can join the arrows with a line for each unit, and start the line path from the actual position of them.
Image
B
104
S
23
G
17
Posts: 1,350
Reputation: 22,028

Post » Fri Nov 08, 2013 1:00 pm

Very nice example. Thanks a lot!
I don't quite understand you about joining the arrows but looking at the example i guess something like that would do the trick:

Find path to (Sprite.Pathfinding.NodeXAt(NodeCount), Sprite.Pathfinding.NodeYAt(NodeCount))

Hopefully, it would give the position of the last node of the path.
Cant wait to go home and test it
B
12
S
3
G
1
Posts: 120
Reputation: 1,829


Return to How do I....?

Who is online

Users browsing this forum: Apollo14, MaujDeveloper and 3 guests