Hi all,
I’m developing a single player game (stealth style) where the player explores an environment trying avoiding enemies, every game object representing enemy npc has attached some C# scripts for handling enemy AI (for searching and attacking player, … ).
I’m starting to evaluating how much cost to develop also a multiplayer version of my game, where there will be 2 players.
I’m a bit confused about handling enemies AI in a multiplayer environment, I’m supposing this solution:
Developing a code so that my multiplayer framework will communicate position, rotation, (mecanim) animation between remote clients, how can I migrate enemy AI logic?
I’m starting to look at the Photon components (realtime, pun+, server…), but I think that before I should have the correct answer to previous question.
Any suggestion is appreciate.
Thanks.
The usual solution is to run the AI logic on the “server” (either an independent computer or one of the player’s machines). Once the AI has run on the server, you send the results as control data to all of the clients. This control data could be as simple as position and rotation, or as complex as animation states, joint positions, and all that. It depends a lot on your game.
Basically, think of the AI as other players in the game, except they all run on a single machine, but the clients just see them as things running around the world that they don’t control (just like other players).
It’s very interesting your solution!
So it becomes important that, attached to enemy game object, it will be the logic to decide which instance of that game object will be the “server” instance and which instance will be the “client” instance; in this way the “server” instance will calculate for example the new position and will send it to other player’s machine, meanwhile other “client” instance not will calculate anything and it will wait for new coordinates.
Is it correct?
Maybe the logic could be that the first client that enters in the room become the server, till it’s connected to the game…
Yes, I think you get the main idea. There’s really no one, single correct answer. It’s all about the game you’re making, how much you care about cheat prevention, if you have dedicated servers or not, etc.