So I’ve got a game where. Or well let me just simplify this.
There is 2 teams. Each team has 5 units, each team spawns at the other end of the map.
Each teams 5 units (Humanoids) will then walk to the other side, now I need to do checks to see if they are near each other (within like 500 studs of each other) and then order them to move to each other and attack.
But what I wonder is, what is the most efficient way of doing this? Cause the game will have more than 5 units.
If I’m checking the surroundings of 1 unit (possibly 50+ times) a second, I’m gonna guess that will be bad. So I’m wondering how I should go about this? Thank you/
So I just add all the rootparts to a table and iterate through them checking each ones magnitude? Cause that sounds kinda intensive isn’t it? Looping through lets say 100, and then doing that for every single unit?
You can do this. I recommend labeling the AIs according to which team they are on, too. You can do this by adding all the units of the teams to respective tables, or tagging them with CollectionService. This will help to avoid looping through all AIs and only the enemies.