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?
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.
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!)
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.
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.
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ā).
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.
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.
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
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.
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!
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