Multiplayer tutorial 3: pong

18

Index

Stats

31,312 visits, 109,723 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 22 Apr, 2014. Last updated 11 Jan, 2022

Common group

The Common group has events that are used for both the host and peers.

When peers connect and disconnect, we add a log just like in the chat tutorial.

Regardless of if we are the host or the peer, we always show our own paddle by our own mouse.

Sync object does not transmit which layers objects are on, to save bandwidth. It never changes in this game anyway, but this event makes sure they always appear on the correct layer.

The host and peers update their GameState variables differently, but we can handle its value the same: if we're in "getready" or "go" state, display some text in the score display.

Finally when the game is in "started" state, we display the score held in the points variable of each paddle. Both players see the host score on the left and the peer score on the right, corresponding to the position of the paddles. The host paddle can be picked by matching its peer ID to the host ID, and the peer paddle can be picked by checking its peer ID is not the host ID.

Conclusion

The general model of a multiplayer real-time game is:

  • The host has behaviors enabled and actually runs the game logic.
  • Peers have behaviors disabled and just uses "sync object" to passively watch what happens. However they can influence the game from their client input values, which the host reads and uses to influence the gameplay.

Pong is a simple example, but still involved 40 events. This example has also not covered local input prediction or lag compensation. Designing multiplayer games can be challenging and can take some time to learn. To move on to the final concepts in a slightly more complex game, move on to Multiplayer tutorial 4: real-time game.

Next Tutorial In Course

Multiplayer tutorial 4: real-time game 25:38

Learn the advanced concepts of real-time multiplayer games, including input prediction and lag compensation.

  • 4 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Re: "Sync object will automatically create and destroy objects, but when they are created we need to set their peerid instance variable so we can later know which peer the object represents."

    => Why don't we use the Sync instance variable action in order to complete the Paddle object synchronization with its peerid instance variable value?

  • does this tutorial still work? if i am a host i don't see the peer movement

  • как сделать систему очков?хочу чтобы счет у двоих показывало