How do I do pathfinding?!

0 favourites
  • 9 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Pathfinding right now is one of the most annoying problems I'm having. Every .5 seconds the enemies find a path to the player and follow the path. But they seem to have this annoying issue of getting stuck to walls (even after changing the cell size and border. They also like to find the most ridiculous paths where they do loop-de-loops mid path.

    My questions are: How can I make these guys find realistic paths?

    How can I stop them from getting stuck to walls?

    And how can I make the cell size and borders "visible" (So I can design buildings and actually know if they're going to work with this BS pathfinding system.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It could be that your path assessment is too short... every 0.5 seconds doesn't leave much time for them to execute the path before "stopping" to find another path.

    If you can post your capx file, then maybe I can have a look and see what the problem may be if increasing the time (make it like 5 seconds or more) between path calculations doesn't help.

    ~Sol

  • It could be that your path assessment is too short... every 0.5 seconds doesn't leave much time for them to execute the path before "stopping" to find another path.

    If you can post your capx file, then maybe I can have a look and see what the problem may be if increasing the time (make it like 5 seconds or more) between path calculations doesn't help.

    ~Sol

    drive.google.com /file /d/ 0Bx4FI3LqqX93VjZ0bkRMUUxFT0E/view ?usp=sharing

  • Okay, turning your cell size UP to about 20, and the cell border DOWN to about 2 or 3 immediately made a massive improvement.

    With your previous setting, the ewnemy was looking basically for a gap of over 50 pixels to fit through which is why they were having some issues trying to walk around through your structure.

    After changing those setting just quickly - I got swarmed and died almost immediately from about 10 enemies running straight for me with little to almost zero "circle running" or hesitation.

    Hope this helps... but you can maybe tweak even further - 20 and 3 were the first settings I tried.

    ~Sol

  • Okay, turning your cell size UP to about 20, and the cell border DOWN to about 2 or 3 immediately made a massive improvement.

    With your previous setting, the ewnemy was looking basically for a gap of over 50 pixels to fit through which is why they were having some issues trying to walk around through your structure.

    After changing those setting just quickly - I got swarmed and died almost immediately from about 10 enemies running straight for me with little to almost zero "circle running" or hesitation.

    Hope this helps... but you can maybe tweak even further - 20 and 3 were the first settings I tried.

    ~Sol

    Thank you, is there any way to visualize this so I can see what size to make my hallways and stuff?

  • Just keep in mind that your total value for the cell size and border size is in pixels... a cell size of 20 means it will look for gaps at least 20 px in size... and the cell border will add to the overall size (keeping that distance away from walls/solids)

    I suggest keeping the border size smaller (only 2 or 3 pixels) just to keep enemies from "Scrubbing" against walls... but a cell size of around 20 should be fine.

    If you make your doorways and corridors around 30px wide or more with these parameters, you shouldn't have too many issues. Also keep the path re-evaluation time lower, that will help with over-all performance. You can even combine path finding with normal "is with range" of the player style AI - so if the enemy is within X pixels of the player they will not use path-finding any more, but rather rely on direct line of attack.

    If you make your doorways even larger, use a larger cell size - it will be faster. Just remember that it's bascially cell size + border for the minimum gap. You willwant at least a few pixels in "grace" so the pathfinder can work a little easier. I always allows like 10-15% extra space at least

    ~Sol

  • I see that you in the 'on created' (for each created Enemies) have obstacles set. There is no use for that on this point.

    Keep 3 things in mind considering this practice.

    1/ There is only one obstacle map. Give any path-object a new obstacle map, and you give every path-object a new obstacle map.

    2/ Adding obstacles is not enough. You have to Regenerate obstacle map for it to take effect.

    3/ The obstacle map will be ready the next tick. Not inmediatly.

    Same thing for the LOS.

    So in fact, those non moving walls, they need to be added as obstacle only once. Preferable in the On start of layout.

    More. About the Line of Sight (LOS). There is a new path generated when the enemies do not see the player. And this every 0.5 seconds. I dont understand what you want to do with this. They just run to the player. And when they see the player, they just keep running to the postion the player was in the situation that they did not see the player. Because they keep moving on that path that was created when they did not see the player. At the same time, when they see the player, they move 5 pixels every tick towards the player. Making weird moves.

    You do al this afford to keep them out of the walls, with the pathfinding, and then you just murderous send them into the walls at 5 pixels/tick. When they collide with the player they even make jumps that are even bigger then the walls. More about that later.

    First. Consider also this. Finding a path takes time. How much time depends on the map and also and especialy on the computer used. I have posted examples for pathfinding that work smooth on my computer, but dont work on the computers of the people who the examples where meant for. For this reason, i dont do path examples anymore. Your enemies all find a path on my computer. So, on my computer, your paths work. On your computer 0.5 seconds can be to fast to force it to find a new path. In that case, the 'on path found' will only sometimes trigger.

    About the combination Car/Pathfinding. Pathfinding is not avoiding solids. It just guides the origin of the object trough the cell size and border. I does not know the size of the path-object. Your walls are 15 pixels. The cell size is 15. The border is 20. The enemys are 32 pixels. So the enemys need 17 pixels room. But they need to be able to turn (especialy the long ones), so we need to account for the diagonals. And some are really long. So on the corners, they just do not have enough room. And the pathfinding is pushing them in the walls. The pathfinding dont mind this.

    But then the car kicks in. You have it set to stay out of the solids. That happens with a 'push out of solids routine'. Between the redrawing of the screens, meaning you dont see it, every solid that gets pushed into a solid gets pushed out of that solid. And that is how this works. Simple as that. So, the pathfinding is pushing it into the solid, the car is pushing it out of the solid, the pathfinding is pushing them into the solid, the car is pushing them out of the solid .........

    And this way a lot of them get stuck.

    About the combination Car/Jump by pixels every tick. The walls are only 15 pixels. You make make jumps of 30 pixels. And jumps of 5 pixels each tick. So you push em into the solids. The car is pushing them out in the shortest direction (in the direction that they the least overlap). A lot of times you jump them so far in the walls, that the car is pushing them out in the other direction then that they came into the wall. Thats why they jump over the walls.

    I understand what you want to accomplish.

    I suggest, make the cell size at least 30, have to experiment with the border, but i think 10 should be fine. Have to tweak with try and error, so they dont touch the walls. Make theire collsion polygones a few pixels smaller.

    Dont regenerate the obstacle maps for non moving objects.

    You dont need the LOS in your concept, i think. At least stop them moving on the path when they have LOS.

    Dont force them to find a path so often.

    And above all. You need another way to jump them towards the player. Probaly using the car controls. That way you dont break the car's solids behavior.

    I think the walls can be a bit wider too.

    Sorry to give you so much info, doubt it you will even read this gd long read. I would probaly not.

  • Wow I didn't even notice there was a car behaviour on the enemy - you're right 99. That's also gonna be causing some issues.

    ~Sol

  • Ignore this I don't know how forums work so I quoted you to notify you.

    I read everything you posted and put into the project. I noticed all the path finding issues seem to stem from the "longer" enemies. It appears they seem to be the ones getting stuck to the walls. Even changing their origin points seems to have no real affect on them. I'm seriously about to just remove every enemy type that's not a 32x32, 64x64, etc... cube so they can pathfind correctly!

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