[Feature Request] New event for Pathfinding

0 favourites
  • 7 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • In my project a solid tilemap is randomly generated and right after that the obstacle map is regenerated.

    Later on the "find path"-action is triggered on a enemy-sprite since i want them to move to the player as soon as possible.

    In "path found" i start the movement as usual but the path which was found is always a straight line to the player ignoring all obstacles

    BUT if i put a System.wait(5 sec) after the "regenerate obstacle map"-action it works correctly. so i guess the regeneration of the obstacle map is an asynchronous process. But in that case there should be an event like "on obstacle map regenerated" where i can hook in to start the pathfinding.

    Or did i something wrong?

  • You probably need to wait 1 tick for the tilemap to be populated before you use it to generate the obstacle map.

  • Thanks for your feedback.

    Well i don't think so since "generate obstacle map" is executed right after filling the tilemap without delay. to make it work i needed to put the "wait"-action after "generate obstacle map".

  • Wait 0 second could also work but your game may lag on older computers or mobiles when it happen if there are a lot of events happening at once on that particular tick.

    Test both and see which one works the best for you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Regenerating the obstacle map is not done instantly, it's performed after your events. Colludium is right, you have to wait until the next tick. From the manual: https://www.scirra.com/manual/154/pathfinding

    "Regenerate obstacle map

    Determine whether each cell in the obstacles grid is an obstacle again. This is a very CPU intensive action and should not be used regularly. If only part of the obstacle map has changed, prefer to use one of the Regenerate region actions. Any changes made by using Add obstacle, Clear obstacles, Add path cost and Clear cost will take effect the next tick after this action. Note this means if you attempt to find a path immediately after this action, the obstacle map won't have been updated yet; add a 'Wait' action with a short delay to make sure the updated map is used in that case."

  • Sethmaster Wait (0) is not sufficient. 500ms works for me. maybe ~16ms (duration of a tick) does the same job.

    But why do you not like the idea of having a new event which indicates that pathfinding can be safely used. using a system.wait to achieve this does feel like a dirty hack.

  • Wait 0 seconds doesn't work for this because it postpones the following actions until the end of the event sheet, not until the next tick.

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