I've implemented basic A* pathfinding in my top-down 2D game, and I'm almost ready to test it, but I thought of something while adding the movement code to my enemies that I think could affect the pathfinding.

My tiles are 64x64 px, and most enemies are as well. However, I do have some boss monsters that are larger than that. My initial thought was that to move to their goal, they have to move toward each node in their path, and to determine whether they've arrived at that node and to start targeting the next node, I need to test the distance between the enemy and their current target node. So what happens if, for example, their next node is next to a wall, and because of their size, their center is too far to "reach" the node?

My solution to that would be to check if the distance between their center of mass and the next node location is less than half the enemy's width plus maybe 10 px. However, what if one of their movement nodes is in between two tiles, and they're too large to fit through the two objects the node goes between? Is there a simple way to modify A* that takes size into account?

  • 2
    \$\begingroup\$ Presumably you consulted past Q&A including Pathfinding for units of variable size, Pathfinding with different-sized units, Path finding in grid for objects that occupy more than one tile, Multi-tile agent path-finding algorithm, etc? (to list just the first five search results) How have you tried applying these suggestions to your project so far? Did you run into any specific trouble? \$\endgroup\$
    – DMGregory
    Sep 10, 2019 at 2:23
  • \$\begingroup\$ @DMGregory Well, munificent's answer on the third one seem's plausible, but the accepted answers for the other questions either point to dead links or aren't relevant. I'll give munificent's answer a try. \$\endgroup\$ Sep 10, 2019 at 2:51
  • \$\begingroup\$ Sounds good. I'll mark this as a duplicate for now. I've also added an elaboration on munificent's answer that will let you handle a wider range of pathfinding agent sizes with a single map array, instead of creating new maps for each size of agent. If you run into any trouble making these work for your case, please edit your question to detail what you've tried and where things went wrong, and we can re-open it for answers specific to your issue. \$\endgroup\$
    – DMGregory
    Sep 10, 2019 at 17:08


Browse other questions tagged .