I think that one of the biggest problems that come when developing a tower defense game is how the towers find their targets. And even though there are multiple ways of achieving that, it almost always comes back to the looping.
I find the method of having to loop for every single tower through every single enemy extremely stupid and a disaster to come in terms of performance, considering it needs to be done many times per second, although I can’t think of any better methods.
I will be grateful for any tips or strategies I could use to make the target acquisition for towers faster and more performant.
Most of the time they only update their target only once a second whereas they are always looking multiple times a second. The trick is to assign a target to them only once a second and then have them always be looking at them/playing their shooting their animation and then if they see that they are dead then they just remain idle until they get assigned again on the next second. You should play some tower defense games on Roblox and notice the behavior of the AI also.
Another example may be tower defense games. There are enemies that are advancing in a route, and the towers of defense look for with the engine, enemies that are in range of attack, if so, they attack. Once you have eliminated the target, look for another enemy in range, if there is one, attack, if not, keep doing checks on each frame or every X frames in the search for another enemy
I actually played TD games like tower defense simulator a lot, and I don’t really think that’s the case, they switch targets instantly when one enemy gets in front of another, definitely not updating once a second
This does help a bit, and spatial partitioning is a must have to some extend, but with or without it, average TD game tactics is having all the towers very close to each other, causing again having to iterate through MOST of the units anyway.