Hi,
In the last couple of days I’ve been reading a lot about multiplayer in Unity and in general. I have an action RPG game that is nearly ready and I’m thinking about adding multiplayer at a later stage post release.
From what I understand there are multiple ways to handle synchronisation of data between the different connected clients. For example, it’s pretty obvious that the other human players can be synchronised with NetworkView that automatically syncs position and rotation of an object across clients. But what about the 50 enemies that are using pathfinding and local avoidance? How would you sync the AI across all clients? Does the entire AI logic have to be on the server?
For example, does the server have to determine “spawn enemy there, now go there, now attack this player, now cast a spell on the other player”, etc etc.
What’s the best approach of an action RPG game?
I am also working on an action RPG with (cooperative) multiplayer support.
The AI logic doesn’t necessarily have to all be on the server. RTS games like Starcraft avoid syncing large amounts of enemies by distributing the simulation on each client. However, having each client handle AI individually and end up with the same result requires a deterministic game engine, and that is going to be very hard to achieve in Unity.
Instead I went with having the server control all the AI. The clients only see the end result of the AI via synced rigidbodies and animation states of all enemies. I then use RPCs when enemies want to interact with remote players and vica-versa, for things like damage. It is useful when taking this approach to separate the decision-making code that should only be run by one client with the rendering code that needs to happen on all clients.
Before worrying about the network overhead of 50 enemies just try it. If it ends up being a problem then you can try to optimize it, and if it isn’t a problem then you’ve saved yourself a lot of time over the distributed solution.
For the position of mobs, I don’t understand why a network view attached to them would not work as well.
Then for spawning, the server has to know where and when it happens, so if the mob handles itself, it must talk to the server, and then the server will tell all the players where it is, or the server handles the spawning directly, and instantiate the mob threw the network to all players. The pathfinding in my opinion does not have to be handled on the server, only directly by the mob, and then the network view does the job. For the spell casting, the mob handles itself, but has to tell the server what it does, and then the server tells to every player the action.
There should be other possibilities of course, but this one should work !