javascript – How often should you calculate the path from mobs to the player? Share your ideas


The path search is carried out through the A* algorithm
Imagine there is a character who runs on a plane, all these mobs should look for him or other possible targets, how often it is worth calculating the path to the player, because it is resource-intensive.
Share ideas on how to build a path to the player.


Once I wrote a game like pacman, I will share my thoughts.

The maximum recalculation frequency is limited by how often mobs can turn. As far as I understand, while they go from one cell to another, it is impossible to change the route. This means that you need to recalculate the path no more often than when the mob has completely entered the cell, i.e. is located in its center.

The maximum frequency is also limited by the performance of the device, as php5engineer correctly pointed out in the adjacent answer.

The minimum recalculation frequency sets the "aggressiveness" of the mobs and determines the gameplay. It could be, for example:

  • On each cell – a very angry pursuer
  • On every 10th cell there is a rather inert pursuer, like a bull in a bullfight.
  • On every 5th and only if the player's character is within a radius of R cells.
  • Once every 2 seconds, regardless of the speed of the mob
Scroll to Top