What would be the most lag-friendly way of controlling hundreds of NPCs that just move towards the closest player (no need for pathfinding as there would be no obstacles) through one script?
Essentially I want to achieve how games like Zombie Rush implement a lot of zombies in their games.
Initially I just thought of using moveto() but I’m afraid that might lag out the game eventually. Would some sort of raycast towards the closest player be better?
If you indeed have no obstacles like just a flat part that zombies are going to walk on what you could do is have the server use magnitude checks for every zombie every half a second or so to check the closest player to them. You could store zombies in a table and just update their positions with some simple math to have them move toward players at a set speed. Then you would just replicate this data with something like ByteNet and then have clients render zombies. Obviously theres alot more you can optimize with this like only sending zombie positions that are close to a client and updating zombies less of the time that are farther away. I would take insipiration and look at the methods tower defense games use to handle lots of moving enemies at the same time. Plenty of topics already about that on the dev forum.