How Handle And Aproach NPC AI?

I want a lot of hostile NPCs, for a wave game, where they have shoting weapons, and I dont know how aproach the problem. I was thinking in making a Module Script, maybe call it “NPCS SPAWNER”, with some global methods just for spawning NPCs. I was thinking to have only one script for the AI, maybe call it “AI CONTROLLER”, using collection service for starting the AI as soon a humanoid is tagged, (the NPC SPAWNER module script will take a position, some arguments and a character with a humanoid and add it a tag) and then use Bindable Events, created from the same script, for constantly updating loops functions of the npcs, like walking or searching for players, but maybe is better to make each NPC handle itself? Could not be bad updating all NPCs at once in terms of performance? How does other games do? Its there a better aproach?

Any help and experiences are appreciated

And what about coruntines? I should care?

I was thinking too, just making the NPCs a HumanoidRootPart, in the server, and render the rest in the client, and disable some humanoids states for performance

if your gonna have a lot of enemies I recommend not using humanoids for that, personally I like to just use normal models with object forces and an animation controller.

as for the behavior you can use modules to specify various behaviors, have one folder for basic actions, and another for complex actions, basic actions just do basic things like move from one point to another while complex actions take specific context into account, the target its facing,environmental status,etc.

its a lot to explain, If you want to see an example of how I do it here’s my project with some complex ai ive made:

for a wave based game as you describe you may not need this level of complexity but having everything in a module just makes the process so much easier.

as a side note, you have the right idea for collectionservice, you can use that to run code on as many npcs as you want with just one script.
I don’t ever use coroutines but I find that task.spawn() works just fine.

2 Likes