How do I cancel find path to request?

0 favourites
  • 11 posts
From the Asset Store
Move around the rectangular and travel as much as you can!
  • Hello, I am stress testing pathfinding on Construct 2 and I would like to know if there is a way to cancel the request to find a path and replace it by finding a path to something new.

    I have a condition that triggers actions when path is found under each of the 1000 objects, the only problem is that if I click somewhere else, they end up trying to find a path to the new location, some move, but by the time they arrive to the second destination, the found path triggers for the first path and makes the units move from the second point to the first point again.

  • I don't think there are any way to stop it as it done in "external". Actually thought if you triggered a new find path, it would cancel the last one. Are you sure that your code is correct?

    Also they are planning on improving the path finding as far as I have been told as its pretty weak at the moment.

  • Gotcha.

    Doing find path again didn't clear out the previous path, it just creates another order on top of the current order that it follows if it is easier, then after following that second order, it goes back to following that first order.

    I even tried disabling and enabling pathfinding, but nothing.

  • Damn, I expected that after buying a License I would get more support.

    Is there really no way to cancel the request to find path to something?

    If not, can it be implemented.

  • Have you tried FOR EACH?

    I also just tired RTS example, and they don't go back to previous path point.

  • If you make lots of objects find a path through solids, not all will find a path instantly.

    Some will wait till it triggers that they found a path.

    If some of the units are still calculating the path and you click somewhere that is easier to calculate, they will move there first. After moving, the initial calculation for a path triggers the move along path yet again, making the unit move to the first waypoint rather than staying on the second.

    I tried thinking about adding a global way point trigger to let the AI know not to follow any old commands, but I have not been able to get it just right yet.

  • If you are really using 1000 objects, good idea might be to group. Let's say every 50 objects you add 1 to variable Group, and every tick or milliseconds you will calculate path for next group. At least this way you wont be calculating for all of the 1000 objects at the same time, and it will give those behind some time to recalculate the path.

    It is going to be tricky. you'll need count amount of objects based of their distance first. if 1000 of them is close, you will have to group them starting from direction of the mouse click. I don't know precisely atm ( really tired ).

    OK, Another Idea, which might be better, is to spawn several nodes/zones towards destination, before looking for path, and chain it, so they will look for first node first, then whe they arrive to first node they will look for second etc. This will significantly shorten path calculating.

    EDIT@ So, had one more thought about it. And in theory that's how I would try and program it:

    Have an invisible unit, super fast, that will be spawned from the nearest selected unit, and will go shortest path, dropping nodes on it's way, every number of pixels passed, and each node have variable for that node +1, so node one is 1, node 2 is 2 etc. Then check one by one for nearest unit ( or use loop to get a number of nearest units. You might ask on the forums how to do it, cause i don't know; maybe look in to this ), selected but not moving units, and trigger on their path towards first node. For each one getting in the area of that node, find new path towards next node. And when you change the final destination point, destroy the nodes and create new ones.

    Should work!

  • Those are actually some good ideas metatronx.

    I was already planning on grouping, but not the invisible node creator. That is cool.

    My point for this test is actually to test the CPU usage of the AI by creating unreal circumstances, like 1000 objects with AI. Grouping them at this point would be counter-intuitive.

    I can do the thing with the nodes, but would it not cause more CPU usage that each 1000 units are requesting a path to that point? Though, I do think you are right. Whenever I make all 1000 units find a path that doesn't require avoiding obstacles, they all find a path and move at the same time. Once there is a path required, they start to move at a pace of about 10 units per second, which makes the units look like a smooth river with good coding. The units only start moving on the path once the "path to" has triggered as a path found.

    So it may indeed help increase how many units can move at once to a far path by using an invisible unit to create nodes on the way to the path, but it could create choppiness as all 1000 units try to find a path to the next, nearby node, on every node they reach. I will do some tests.

    Here is an example link, follow these instructions first.

    Test your theory and you will see it works.

    To test my problem,

    when game starts, click near the entrance of the spiral.

    All units should move ok to that spot.

    After they arrive, click inside the spiral.

    They will form a river and start moving towards that spot.

    While they are moving, try clicking outside of the spiral near an open field where no obstacles exist.

    The units that had not found a path yet will move there first, then find the more complicated path after computing and then move back to the inside of the spiral.

    https://dl.dropboxusercontent.com/u/205 ... index.html

  • Yeah, that's why one of my suggestion is to controlled delay of pathfinding. This might work. Maybe there is a way to copy path to all units standing in the same place. Then again, they shouldn't really - they should stand next to each other.

    I want to make rts when I finish current project, so I will definitely be using my own ideas

    EDIT@ AHhh, I know what to do!

    On click: Set global varGOGOGO to 0, Look for path.

    Unit.On path found: add 1 to global varGOGOGO

    (For all selected units), global varGOGOGO = Units.Count, for each Unit: Move along the path.

    Try that It will delay all instances till the last one finds it's path. Might work.

    Also, what is the size of the grid you are using?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The grid is 10x10.

    Yeah that could work, but keep in mind you can't cancel that request, so some will continue to look for that command even if you issue new commands.

    I am not new at coding by hand but I am new at Construct 2, but I am getting the hang of things =]

  • Well, as last resort you could destroy and respawn the sprite within same tick.

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