Multiplayer tutorial 4: real-time game



Features on these Courses



40,808 visits, 170,679 views



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.

Login layout

This layout is virtually identical to the previous chat room tutorial login layout. It simply serves to allow the user to enter a username in to a text box. The username is stored in a global variable and used to log in to the signalling server on the next layout.

Game layout

The Game layout has the objects for each player so the actions of other players in the same room can be seen and responded to. The layout also contains a simple chat feature with a text box along the bottom of the screen. Each player is represented by a Peer object with an associated PeerName text object (appearing as a label above them with their name and stats), an AimSpot object (showing where they are aiming with the mouse), and a PeerLaser which appears when they are firing. These objects are all in a container together. This is very useful for being able to have all the objects created and destroyed together, and automatically picked together in events so they act as single unit.

The layout also has three layers: "Game", where the peers appear; "Lasers", where player aim spots and lasers are placed so they always appear above peers; and "Info", where name labels and the log appear above everything else.

The events for this layout deal with everything the previous pong and chat examples did, since it also has a built-in chat room. However on top of that, it also deals with:

  • syncing more data and variables
  • sending more detailed peer inputs to the host and using input prediction locally
  • performing hit testing with lag compensation when host

This is a relatively complex example, with a total of 81 events. We'll begin looking at these events on the next page.


  • Order by
Want to leave a comment? Login or Register an account!
  • Excuse me, i have question.

    On my project, peer alwasys follow host. what wrong? Mr Ashley

    Thank you


  • Please help me im trying to add a button ive tryed so many things but it will only show on one screen

  • You guys should ask on the forum not here.

  • I think there is something wrong with the code, perhaps, updates over the years messed it up. I have tested the game as host and peer, the host moves fine but peer's movement is somewhat restricted.

    EDIT: I realized it works fine when screens opened side by side however if you use "Remote Preview", than the peer does not move propoerly.

  • Not working anymore. Even the example seems to be broken

  • Load more comments (2 replies)