I’m creating an RTS-style game, and while I have AI set up for my actors (turrets, tanks, etc) that works fine, it doesn’t scale well. Once a few dozen actors are present, my game starts to slow way down.
I need some guidance on how to design my AI so it scales well. What are some techniques I can use to reduce the workload?
I’m currently using Behave’s behavior trees to handle the AI. Is there anything I should be aware of when using Behave for an RTS-style game with many agents?
I do not have links, but here are a few thoughts that come to mind:
If you have a general slowdown you might try to reduce update rates. Reducing it from say 200ms to 500ms might not be noticable in the game but double your performance. It might even look more natural if the actors take some time to think.
If you have a lot of actors you might experience performance peeks or stuttering if you have a lot of BT updates in one frame. For this you might want to cap the number of updates which are allowed in one frame.
Another idea might be to move the AI to a separate thread altogether. You will have to spend some work on synchronization and it is a tricky task however.
Code optimization might help you if your AI code has poor performance. Profiling will help you find the bottlenecks.