I’m beginning work on an NPC system. The tasks that the NPCs must accomplish are as follows:
Spawn within a specified amount of studs of players at random
Choose a random nearby goal position, travel there, and when reaching that goal choose another
Engage in (Breath of the Wild-style) combat with players when within range, change targets based on damage dealt over a specified period of time
Engage in combat with enemy NPCs
Since this is a multiplayer game, what I’m most concerned about is the server strain that an NPC system like this would cause. Calling :MoveTo(), using PathfindingService, handling combat, etc., seems like it’d cause a lot of stress. Very curious as to how games with sophisticated NPCs manage to function and the feasibility of a system like this.
If you’re still not getting good enough performance, you can try using crazyman’s approach of only rendering those that are on-screen. Takes a bit more effort in terms of figuring out where they should be on the server and replicating but very performant:
Interesting, I’ll definitely keep this approach in mind if I need to render a substantial amount of NPCs at once. (Thanks for the video @Crazyman32) My main concern at the moment isn’t so much a drop in FPS because of too much geometry or moving parts, but instead an extreme amount of strain on the server that would cause high ping due to constant server load.
I run about 57 NPC in my KonoSuba game tests and I see 0 strain. Make sure you disable the humanoid states you aren’t using and you’ll get so much better literal performance.
That webm was from 3 years ago so I understand the framerate was pretty mediocore, but they did run smoothly in my game with a situation more realistic (more than just NPCs)
I would not manage them on the server, while they may not strain the server, it will make the client lag, instead I would make an invisible hitbox on the server, and on the client create npc’s with the linked hitbox, I would move the hitbox on the server and generated paths to new hitbox’s position on the client, doing this on the client will help you save a ton of performance by only rendering npc’s in the view of the camera.