Questions about custom humanoid implementation

I recently have been looking into making a custom humanoid solution to handle lots of NPCs in a condensed area, all of these NPCs would be moving a lot and likely pathfinding. I aim to have 250-300ish NPCs without lag but I could probably get by with 200.

The main issues I’m running into are just conceptualizing how a system like this would work at a technical level. My current idea is to have a root part on the server that controls position/state and then animate and render clientside. The issue with this I can’t figure out how to solve is keeping the positioning the root part above the ground while also allowing for movement. My first idea was to just raycast downward at the X and Z coord the part is at and position off that makes it hard to do things like jumping, I could possibly tween the offset from the ground but tuning it to look exactly like a normal jump sounds not possible.

my next issue is about movement. I see a wide variety of solutions other people have used to move a custom humanoid. Some use lerp, some use tweens, some use BodyMovers, etc. The simplest solution I can come up with is just changing the root parts position on the server but doing that every heartbeat for ~250 parts sounds extremely inefficient. Maybe I update less often and compensate on the client, but then that makes my NPCs teleport around if the direction they are heading in is suddenly changed.

My final question is about pathfinding: obviously pathing for 250 NPCs individually isn’t possible. The issue I face is that my map isn’t dynamic so I can’t create a flowfield or node system to help path. My game centers around the players being able to build defenses to survive NPCs, the base game is almost completely flat and objectless but players can very easily build massive and complex structures. I don’t know how I can pathfind around these.

overall I’m pretty stuck and would appreciate any help I can get. Thanks!

Fortunately, @Atrazine has already solved this problem.

Key points for you:

  1. Client rendering server pure data, avoid physics and default roblox collision which is excessive and computationally expensive.
  1. Make the game more simple, force them to build in a grid or adapt what they build to fit in a grid.

These are the sacrifices you must make for performance on Roblox or well any other game engine.

forgot to mention it is constrained to a grid, although the shapes of the grid components vary greatly they are all cuboids so I can probably work off that. I’m unfamiliar with grid based pathfinding systems, do you know of any that would allow me to calculate 3D paths? I was originally going to only path 2D but considering my max grid is 200x500x200 I think it shouldn’t be that much more intensive to calculate paths that involve climbing (with much higher weight to 2D movement, I don’t want it climbing unless it has no other way of reaching a player), correct me if I’m wrong.

This is a different topic, I think you could research this on your own but for 3d and grid paths all you have to do is modify the :GetNeighbors of your A star pathfinding algorithm instead of searching grid[x+1][z+1] you will also add grid [x+1][z+1][y+1] and add that y dimension if it exists.

I will link a good source here:

1 Like