So i’m trying to work on some squad-based AI, and i’m running into a bit of a coding problem.
How do i efficiently acquire targets within a radius?
would it be easiest to go through a table of all enemy units? or just check all units within a region3 of it’s range?
Ideally I’d like to have a high amount of units on the map, so i’m not sure which if these would scale up better with increased unit counts.
Using magnitude should be very inexpensive, but it does depend on the amount of enemies (and type) you expect to be finding. If it’s players then magnitude is easiest, but using custom enemies in large quantities region3 might be better. The ideal solution is to test multiple approaches and see which works.
I think i’ll go for using both to a degree,
region3 to get go from about 100 possibilities, down to however many are within range, i then switch to magnitude.
while i can’t use spherical detection for the region 3, I find that a square with radius of the max range, and then magnitude check starting at the max range.
now for the bigger question. how often can i call this on the server before I start to experience slowdowns?
That’s definitely something up to stress testing really. You should go by what is a smooth experience, but do remember that it’s probably not actually necessary to do it all that often. If I had to guess without any idea of what your game is like I’d say every second could work.