Artificial (OOP-based) humanoids and how to create them?

So I’ve been wanting to create a game with a general “defend x until y” atmosphere to it, something similar to Defend the Statue by 885sdwsdw. A a game such as this would most likely require a lot of Humanoids as enemies for players to defend against in the first place, and I’ve heard that Humanoids aren’t terribly efficient at what they’re designed to do.

So my question is: how would I create some sort of artificial humanoid class? I’ve read up on object-oriented programming and I kinda understand it, and I could manage to wrap my head around OOP given some time and practice.

What confuses me about artificial humanoid creation with OOP is the act of actually creating and replicating custom Humanoid bodies on the client. I can’t seem to grasp this concept. I’ve heard about people creating “torso” parts on the server and having the client build the rest and I just don’t understand how to do this. Raycasting to elevate the torso part wouldn’t be too difficult, and movement probably wouldn’t be either. I just have no clue how to do this.

(This is of course assuming artificial humanoids are even necessary for a game like this. I’m not sure they wouldn’t be but who knows :man_shrugging:)

Anyways, would it be possible for anyone to source some work or explain this concept? I think it’d help a lot, as I learn easier when I’m actually experimenting with code itself rather than reading it. Thanks :slight_smile:

2 Likes

Yes, Humanoids can be bad if you’re running badly optimised code and lots of them (hundreds). But also remember that Humanoids are still fairly performant; we already have 100 player servers, and for many years badly-optimised RPGs have been created that have hundreds of NPCs and still perform well (do a degree, at least).

Remember that you will probably not be going over 100 NPCs most of the time except if you decide to make your game large-scale (or have a high players-per-server count). Even then, 200 NPCs probably won’t kill your game either. I’ve run my own tests and I’ve found significant issues starting at around 250-300 NPCs in my RPG, provided my code is optimised. I would usually expect maybe < 20 NPCs alive at a time in a game like Defend the Statue.

TL;DR; The built-in Humanoids work just fine if you don’t have insane amounts of NPCs and have optimised code :wink:

4 Likes

I would suggest using Roblox’s Humanoids… It’s not worth the hassle to create a custom humanoid especially if you don’t need any extra functionality and even if it might give your game a slight performance increase. Good luck on your game by the way :smile:

1 Like

Thanks! Appreciate the response from you and @Hexcede. I shall trust in the power of ROBLOX humanoids :stuck_out_tongue:

1 Like

When it comes down to NPC’s and AI, the actual humanoid is not going to have alot of impact. However, you should consider a few things:

If your NPC is going to perform a familiar action to others, have it so it loops through every NPC every few seconds (If it requires something instant like attacks or something, have it check more frequently, if its idle, then you won’t need to check as much), rather than having individual scripts for each, and have one central script that performs the actions for them.

You should also make sure to consider the space that those NPC occupy, as moving objects in one space can cause alot of physics and render lag. From experimentation with my own system, you can get about 250 NPC’s on a low end machine at once, as long as they are spread out and the code is well optimised.

oh and if you wanted to do animations, think ab doing them on each NPC on the client (i’m not sure of the impact of this but i’m assuming it puts less on the server)

2 Likes

If your NPC is going to perform a familiar action to others, have it so it loops through every NPC every few seconds (If it requires something instant like attacks or something, have it check more frequently, if its idle, then you won’t need to check as much), rather than having individual scripts for each, and have one central script that performs the actions for them.

Would CollectionService be good for a task like this?

1 Like

Yes! Infact I use that service quite frequently to tag Idle and Hostile NPC’s.

You should also add a generalised “NPC” tag and add a “HasTag” check to see whether they’ve died or not (given you remove the tag on death)

2 Likes

Thanks for the advice.

1 Like

No problem.

1 Like