How to fully optimize zombies?

Hello!
I want to create zombies that are smart using pathfinding and at the same time also optimized (meaning I can handle hundreds of zombies smoothly).

Some stuff I know I can do:

  • Raycast from the zombie to the closest player and see if pathfinding is needed or if the zombie can just walk towards the position
  • Only target a new player (or check for a new target/pathfinding) after enough time has passed (50 zombies checking for a new target every 0.1 seconds vs checking every 4 seconds)
  • Disabling states unused for humanoids

I’ve tried to do this before (even without pathfinding) and at around 50 zombies I noticed the zombies moving a bit slower (but barely) and at 100+ zombies their movement was incredibly slow, probably because the server couldn’t handle all the zombies. It could have been the huge amount of humanoids, though I hope I just missed something I could’ve done to make humanoids have better performance.

I’ve heard humanoids right now are not very optimized (even with disabling states etc) but I kind of need them since I want my zombies to be able to jump up to places, walk up hills etc and it seems like it’d be a lot more work to either:

  • Create a custom humanoid
  • Use no humanoids and manually tween the zombie’s position (doing this up hills or jumping realistically seems like this would be hard to do)

I also wonder if I should make zombies R6 or R15 (R6 less parts, R15 better animations). I’ve seen people suggest only one part is on the server and the client creates and tweens the zombie, but I don’t know how good that would look and I’m not sure how I could control one part with a humanoid while having it look the same as just controlling the whole zombie on the server.

My goal is to have zombies that can use pathfinding to get to zombies, if possible using R15 for better animations, and the server/game can smoothly handle up to around 100 to 200 zombies (if that’s possible). Is there any advice on how I can achieve something like this?

Thank you!

7 Likes

This doesn’t scratch the topic of the post at all. Maybe you should read posts before posting your catch-all answer.

4 Likes

You asked for a optimized zombie, there is a video on how to do it.

By the way, you are not going to be able to find anyone giving info on custom humanoids. Only the top developers know how to do that.

1 Like

There are some methods you can check out in this post. Methods of reducing network and physics lag with large numbers of humanoids (?)

You are not going to be spoonfed the code… :man_shrugging:

1 Like

Humanoids are not required at all if you go about it the right way. Animations can be done with AnimationControllers, and everything a humanoid offers (walking, jumping, stats like health) can be done with simple custom scripts (store health as values or variables, walk using e.g. TweenService).

Reconsider if your scenario really requires humanoids at all - the ideal solution would be single-part characters that don’t feature humanoids, and characters on each client that run only using AnimationControllers.

1 Like

Creating custom humanoids is incredibly hard to achieve and there are 0 concrete tutorials on how to do it.

Thank you for sharing this thread, I’ll try use a few of the methods mentioned there. (Also I don’t want any spoonfeeding, I’d rather have methods on how to accomplish something, but thanks for the thread!)

1 Like

I’ve heard about this approach of using tween service to walk and playing an animation with an AnimationController, it seems like a great idea that I would implement but simulating stuff like jumps that are affected by gravity seem kind of difficult to do. Humanoids provide a lot that I’d love to use (although I disable climbing and swimming states) and I’m having a hard time deciding in my head how I’d go about tweening a zombie going up a hill or jumping up stairs and having it look as real as a humanoid player would move up.

PathfindingService does this for you, for the most part. If it needs to climb a hill it will do that and each of the keypoints will be correctly positioned, more or less, depending on how much the slope changes within the path.

Jumps (and walking) aren’t hard to do at all if your part is affected by physics (just momentarily add to the Y velocity of the part), if it’s anchored, you will just have to simulate the flight path independently (two loops/tweens, one moving the part up and down on a quadratic curve, one moving it to its goal on the XZ plane).

Climbing and swimming are much harder to correctly implement, but you don’t bother with them anyway, so it’s not a problem.

I would recommend trying this out in a test place at least and see how much effort it takes; if it’s hard to do but still simpler than tons of humanoid manipulations then it’s your best bet at not only minimizing but effectively eliminating humanoid lag.

1 Like

Ah I see! I didn’t think about adding velocity to make it look like the zombie is jumping using physics. I’ll give this a try in a test game and see if it’s an effective solution.

In regards to pathfinding automatically making points up a hill, I usually raycast from the zombie to the character to see if pathfinding is actually needed or if I can avoid the need to calculate a path by just using humanoid:MoveTo to the player’s position. Do you think using pathfinding instead every 5 seconds and not using the raycasting would in turn be better for performance over using humanoids, assuming I’m able to make a system like you’ve described to simulate the zombie movement?

How intelligent do the zombies need to be? How avanced are the motorskills of the zombies?

Is humanoid relevant?

Common things people do is that on the servers, the zombies are simple blobs(single part) and then they render them on the client. Also finite-state-machines are pretty useful in the scenario of AI’s having to possess different behaviours and states that are local to the AI.

Pathfinding? Roblox’s pathfinding is very very good at what it is supposed to do… Maybe not in this case though. They’re expensive. Very expensive. A* pathfinding is very common nowadays, perhaps read into that. But you’re on the right track when you’re thinking of calculating and tweening zombies’ movements.

BUT… again,… This question has been asked a couple of dozen times and all of your questions are answered by those predecessors. So… next time look for a bit longer.

2 Likes

Raycasting sounds like a pretty good solution, however I would add that if the Y axis different is more than a character’s height pathfinding service is automatically used because in that case the AI usually needs to find a hill/ledge/stairs anyway. Raycasting is much, much faster and much less costly than pathfinding with Roblox’ engine for both.

Depending on what kind of map layout you have, you can get pretty creative with the pathfinding. If your map is a single building, you can subdivide it into “sectors”, each being cubic regions inside it, representing e.g. rooms. From there on you can make zombies always pathfind into sectors where players are in, and once they share a sector with a player you’re almost guaranteed that a follow or raycast path will make the zombie attack the player, eliminating latency where it actually matters for user experience (“Zombies shouldn’t get stuck when they’re literally two studs next to me”).

2 Likes

As I previously stated. This has been asked a lot of times. I am aware that we are not the stackoverflow community, but it is quite common to be sharked for asking redundant questions. I am just saying… One search and you wouldn’t have to have asked this question.

https://devforum.roblox.com/t/achieving-mass-npc-count/263949
https://devforum.roblox.com/t/the-most-resource-friendly-efficient-way-to-script-npcs/392738
https://devforum.roblox.com/t/best-way-to-handle-a-lot-of-npcs/714464/2
https://devforum.roblox.com/t/how-do-i-load-and-unload-npcs-like-my-restaurant-did-i-need-some-optimization-to-support-a-lot-of-player/715694
https://devforum.roblox.com/t/how-would-i-make-a-npc-be-able-to-open-doors-using-pathfinding-or-raycasting/682163/11
https://devforum.roblox.com/t/achieving-large-number-of-npcs-w-o-lag/751910/6
https://devforum.roblox.com/t/handling-lots-of-npcs/157518
https://devforum.roblox.com/t/ideal-way-to-code-a-lot-of-npcs/338882/13
https://devforum.roblox.com/t/how-to-optimize-humanoids/389801
https://devforum.roblox.com/t/how-do-i-handle-animations-for-a-large-number-of-npcs/142944
https://devforum.roblox.com/t/most-efficient-way-to-have-semi-large-amount-of-npcs/96250/20
https://devforum.roblox.com/t/ideal-way-to-code-a-lot-of-npcs/338882/15
https://devforum.roblox.com/t/any-optimalization-tips-managed-about-1500-npcs-mostly-without-lag/284180

I found this in 2-3 minutes, imagine what you could’ve found if you spent an hour :face_with_hand_over_mouth:

8 Likes

Should there be a group of zombies in close proximity you could have them follow the same path. This will give a good hoard effect and will also mean less paths are being created.

Of course if they are grouped up there is a chance that they will push each other, but personally I think for a brainless zombie hoard it would just add to it.

1 Like

I would want to achieve something similar to some of the top games about zombies near the front page, whilst maintaining high performance even with hundreds of zombies. When joining these games I usually don’t see more than 30 zombies active at one point.

Ideally my zombies can move towards players and use pathfinding to get around obstacles that block them. I’d assume a humanoid isn’t 100% needed but would be simply an easier solution (just using humanoid:MoveTo and pathfinding provided by Roblox)

I have heard of this method mentioned before on the server, and I recall these single part zombies being controlled by a humanoid on the server. I can get my head around rendering the zombie on the client but I’m not sure how I can control a single part using a humanoid, not something I’m very informed on. Finite state machines are something I haven’t considered, I may research more on that relating to NPC behaviour!

If I recall correctly I need to set up nodes across the server to use A* pathfinding, though is this a viable solution if I were to have multiple changing maps (a round based type of game) that are decently large?

I’m sorry, I know this question has been asked a lot but a lot of the solutions I have either tried (a lot of humanoid related optimizations) or I don’t understand. I was hoping for responses that could be explained in a different way to help me understand the methods behind stuff like controlling one part on the server.

I’ve seen a lot of these posts and for a lot of them I wasn’t sure how to implement some of the stuff mentioned.
On one post I read something helpful about calculating the distance between a zombie and a player to determine how long to wait until I next check over players and their distance away from the zombie. Though I only check every 5 seconds, and I don’t think that would be the cause of lag.

I’ve also read a helpful post on optimizing humanoids, but most of the strategies I already used (disabling states) and some I didn’t know how to do (tweening an anchored torso to positions is easy on a flat map, but a map requiring jumps seems harder to do)

Sorry again for the repetitive thread, but thanks for the advice! Finite state machines seem interesting to learn about

oooooh ok ok ok. sorry! :sweat_smile:

Dividing the map sounds interesting! I’m not sure how viable it would be if I were to have this zombie automatically respond to any type of map though (for example if I was making a round based game and creating maps on the go)

Checking the Y axis difference makes sense though and I’ll keep this in mind, thanks!

There are many ways to handle this, but the solutions are small, mainly because the server is lagging, not the client. I’d say to create a oop humanoid and check for garbage using collectgarbage.

edit: handling frameworks, damage, and etc will slow down the client
a direct example is cb at close quarters with enemy.

if it’s with the client however, and you did all these steps it is clearly a different story.

edit2: aka making the orientation, and position going towards the player is not that hard.

1 Like

I wasn’t aware of this, I’ll see if I can understand anything from it to help me!

Dynamic A* pathfinding does sound complex, I’ll see if I can find any ways to implement it effectively.

Ah ok! I’m assuming using bodyforce would automatically cause the zombie to move up hills (and not clip into them) when moving straight, the jumping is the only thing I was confused on, but I have advice on this thread on how to do that so maybe I wont need humanoids after all

Oh ok, and I will respond to old ones in the future, I see where I went wrong with making another thread that re-iterates a lot of what has been already said. Thank you again for your responses and advice!

3 Likes

I now understand what you are trying to accomplish, one thing to keep in mind is that games like ‘zombie strike’ , ‘Zombie attack’ and ‘zombie rush’ do not have pathfinding.

So if you are using path finding for a lot of zombies there will be performance issues.
Keep in mind that long paths will cause more strain. So moving zombies that are far away is a good idea.

Also. dont forget that the players will be moving so it may be that paths need to be recalculated every so often.

edit:
I replied to the wrong person again.
heres a tag so it pings you @Superdexus

1 Like