So I’m making an RPG game and I’ve come across a problem with a few potential solutions. I’m not entirely sure on how to make enemy NPCs spawn and work(this is scripting, by the way). Here are some ways I could do it:
Create the enemy on the server and have a humanoid in it so it can move kind of well. Use physics to move it and have it use default replication to the clients. Is this way not so smooth?
Create the enemy on each of the clients using humanoids with physics and every time it needs to do something, send the data to the client so it can replicate it. Will this come at the cost of the accuracy as to where the enemy is for everyone?
Create the enemy on the server and don’t use Humanoids - instead use various BodyMovers to determine where it should be - this means I have greater control, but is harder to set up. Use default replication, may not be as smooth. Like 1.
Create the enemy on each of the clients, but using BodyMovers and physics like in number 3. Use custom replication. More difficult to set up, but possibly the best option?
I’m not sure what to choose here. Humanoids kind of allow me to do things easier because they already have built-in functions for moving and various things. Would making a custom system with BodyMovers be more efficient than a Humanoid though? And is custom replication needed for this? I already do some custom replication with my projectiles and effects, but I’m not sure if this is necessary for enemies as they’ve worked fine before with Humanoids and being made on the server - though that was a while ago and I do want to do bigger and better things with the enemies now.
Or if there’s another way you recommend, I would love to hear it. I’m not quite sure how I’m going to do this right now…
Create a server representation of the NPC; as a Part, an attachment, whatever. And have that representation hold all the information relevant to what that NPC is doing. Then on the clients, have a “real” NPC and get it to move to where its needed to be (If it lags behind its desired position, CFrame it back to its path to try and keep it as close to the server’s view as possible.) and use the client’s NPC to send any events/functions that need to sent be to the server.
Yeah that’s pretty much what I mean by create the NPC on the client - handle it on the server and replicate it to the clients. Are you suggesting I can store the data for the enemy in an object in the workspace so it replicates instantly to the client? Also, wouldn’t that still lag with a lot of enemies?
The way I see it, you’ve got two ways of sending the information to the client with the method I mentioned.
You actively send changes to the client through RemoteFunctions/Events, with a reference in that table to the enemy you are attempting to alter.
You don’t send it to the client, but instead change a value of a variable within the ‘enemy object’. This will be seen by the client, but you aren’t directly sending it to the client. It just happens that the client can see it too.
I’m sure someone who properly understands networking could give a better example of this though
Also another question, not exactly related to networking - for what I’m doing, using Humanoids is much easier… but is it more efficient? I’d basically be replicating what Humanoids do anyway - keeping the NPC upright, moving to locations, rotating automatically - but I wouldn’t be using stuff like states or some other functions and behaviours Humanoids have. I feel like it might be too tricky to set up for what I want to get out of it.
Basically, if I make my own physics for NPCs and not use a Humanoid, is that going to be much more efficient in terms of physics and script use?