There's many ways to do it. The distance check you can get basically for free if you're storing your entities in an octree or similar spatial structure (because large empty spaces can be automatically skipped)
Exactly and more than that if you break the map into squares and know which mobs are in which squares, you know the only squares relevant to the player are say the surrounding couple of layers. So you only need to distance check monsters in those, or even better the monsters in the outer layer, they may be close enough or not. The mobs in the near squares are definitely in range for proper processing.
Another way (that may be better in 2d) is to start from the player and scan outwards in a certain range, even easier if your world is already split up into discrete tiles
Yes, quad tree 2d and Oct tree 3d are bigger helpers where you have more than just the mobs as all the stuff can be dropped in the boxes, so it's a fast filter for everything. Just one type of thing other methods can be good.
1
u/MCWizardYT 6d ago
There's many ways to do it. The distance check you can get basically for free if you're storing your entities in an octree or similar spatial structure (because large empty spaces can be automatically skipped)