How do I avoid laggy real time multiplayer?

0 favourites
  • 7 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Howdy how's it going everyone?

    I'm making an online top down shooter, close to the example project made in the multiplayer tutorial. I experience though that I have just uppgraded a bit the code (and without syncing much more objects) that the multiplayer is already a bit laggy.

    I've read a thread with a similar concern where people pointed out that it could be a flaw with the peer-to-peer or because of too much syncing/inputs.

    Is it so that I can't expect being able to make a more advanced online-game with a relatively big map, shadows, and a more complex system? Maybe it's too much for HTML5?

    Kind regards,

    Roland

  • Hi.

    You only really need to send the most essential data to peers. Player coordinates, angle & etc. Everything that somehow gameplay-related, not just visuals. There is no need to share the whole map.

    e.g. If you need character's shadow - send only character's coordinates & angle. Shadows should be updated for each peer individually based on that data. There is no need to flood connection with this.

    You could make any online game, but you have to be very smart about what you send.

    Also you'd have to show us what you have updated so we could see what could be the reason for lags.

  • Thanks for that great answer.

    It gives hope! I'm gonna update my code a bit and do some testing. And then come back to this post.

    Yes that's what I understood: I will still need to sync 5 variables and have 6 inputs.

    Does a lot of code/a lot of objects slow down the game? Does putting objects in a container save some bandwidth?

    Kindly,

    Roland

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Without optimization it will. Better make a simple proof-of-concept game first & then work on beautifications (like shadows & amazing explosions).

    Containers are always a good choice. Use them every time you can!

  • It really does make sense.

    This is what I've updated:

    I used the same basis as the multiplayer example, but added some few details:

    - The player can run when the Shift key is down

    - "gunnumber" is not used yet (but it is going to be to let the host know which gun the player is using)

    - bulletx and -y is for hit testing as there is a recoil for guns so they don't shoot exactly where the crosshair is (note: there was lag before I made hit this hit testing)

    Maybe it could be that I use the shadow caster function in combination to the multiplayer? Or that my Internet connection is bad?

    Cheers

  • Looks nice from what I can tell.

    It is not about internet connection. Unless your shadows have some meaningful impact on gameplay aside from visuals there is no reason to keep them updated for everyone. Also some devs introduce settings in their games & have there option to turn off shadows.

  • Thanks!!

    Interestingly enough when I try my game in the same settings but with a more powerful computer I have no issues whatsoever. It seems the script is just too much for my older computer. I could actually even experience some minor issues on the real-time example.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)