0
\$\begingroup\$

Let's suppose a game of 4 players, one is the host.

They will fight many enemies, along the lines of 20-40 at the time. Among other things like sending their own state to the other players (position, rotation, shot this frame, crouched, etc). How do I handle the enemies?

Do the host "decides" the enemies state? (again position, rotation, isattacking, etc). And then sends several messages to the other players so they sync their own game? or do I "divide" the enemies, lets say 40, and 4 players, 10 enemies "controlled" by each player game? and then, each player sends those messages to the other players so all enemies are in sync?

Also, should I group the messages and send one big message instead of 40 little ones? How do I know how big can the message be (how many enemies info in each message)?

Basically I'm asking whats the best way to handle a 4 player p2p game with many enemies on screen.

Any good tip is appreciated.

\$\endgroup\$
  • \$\begingroup\$ Networking is a broad topic with a lot of possibilities. Research some more to narrow it down then come to us with more specific issues. Also, you can talk about broad topics with us in Game Development Chat. \$\endgroup\$ – Almo Oct 31 at 15:20
1
\$\begingroup\$

Do the host "decides" the enemies state?

This is one way to do it. Which I recommend, but there might be games which work with other methods.

Basically I'm asking whats the best way to handle a 4 player p2p game with many enemies on screen.

There is no best way.The simplest way to do it would be to have one host control everything about the game, and all other players are the clients which just get that information from the host. Additionally you can have the clients try to "predict" the enemies movement, until the actual position it gotten from the server.

Depending on the game, other ways might be better. It's impossible to tell that unless we know more about the game you are making.

Also, should I group the messages and send one big message instead of 40 little ones? How do I know how big can the message be (how many enemies info in each message)?

When it comes to sending messages, the general idea is, its better to send one big message, than several small ones. Sending a message over the network has some overhead which multiplies every time a new message is being sent/received.

\$\endgroup\$
  • \$\begingroup\$ I'm thinking on a similar game to left 4 dead, you see LOTS of zombies with not much info each. so I can probably send all their positions etc in one message. \$\endgroup\$ – Lestat Oct 31 at 15:21
  • \$\begingroup\$ @Lestat Usually you would need to send only essential data. For example you wouldn't need to send animation data, and each client can have they own animation states. For most games, it doesn't really matter if an enemy is in a different frame of the idle animation (for example). \$\endgroup\$ – TomTsagk Oct 31 at 15:35
  • \$\begingroup\$ oh yeah ty, makes sense \$\endgroup\$ – Lestat Oct 31 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.