Recalculate paths when obstacle maps regenerate?

0 favourites
  • 5 posts
From the Asset Store
A template which allows you to customise the controls of your game.
  • 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...

  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    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.

  • 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

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