The code gathers all the player-enemy distances, sorts them in an array to find the shortest distance, then for each player sprite, compares it’s distance to the shortest distance in the array to find the closest player.
This player sprite is stored in the enemy sprite data and set as a follow target. All of this happens every game update so that the enemy can register a new closest player as fast as possible.
The array before being sorted. After the sort, the 52.47… distance will be in the 0th spot in the array.
The distances are recorded to such an absurd number of precision that I’ve managed to use this method to register sprite overlaps as the default block can be quite buggy (especially when lagging or when dealing with multiple sprites)
Registering sprite overlaps is the same as finding the closest sprite, but it checks if the shortest distance is also short enough to be overlapping with the player.
Have fun spamming B with these ones as well (just looks cool lol)
btw you need better arrays for the sorting block (oh and also sprite utils for like everthing else lol)