Cuttng AI based lag?
I have AI tanks and auto turrets in my game which deploy to help the team that has less players on it. I wrote the detection script a long time ago and let's just say it is so long and inefficient and poorly thought out that it is causing serious lag problems in my game. The goal of the script is to detect enemies and bullets fired by enemies inside the Al's detection radius. An idea I have as a replacement for this lag causing script is to place all possible targets in a folder and then iterate through these to find the nearest one inside the detection radius. An idea of how this might work:
1 | while true do wait ( 0.5 ) |
3 | if thispartdistance < lastcheckedpartdistance then target = thispart |
I know this script is extremilly quickly drawn up and not even close to functional but you get the general idea. My only fear is that because I will have about 10 tanks and 15 turrets (25 scripts running simaltaniously D:) and anywhere from 10 to 30 possible tangets this method will also glitch out my game. Will this script cause excessive lag? If so is there a better method? I am not requesting a script since it probably would not fit with my game anyway, I just need some pointers on how to combat any lag that may occur from AI like this.