Multiplayer, Lag, and C2

0 favourites
From the Asset Store
Find pleasure in juggling balls with this basic HTML5 template
  • I'm in the beginning stages of developing a co-op platformer (steam), and I have a few questions that I'm hoping some c2 veterans can help me on.

    1. Conceptually, I usually have 1 sprite (box) for the platform object and another sprite for the character. I then either pin the character to the platform box and everything works wonderfully. On the peer when connected to a host, the collision box runs fine, but the character sprite lags behind (similar to if you pinned something to an already pinned sprite). Is there a better way to do this in multiplayer? I have both the sprite and collision box syncing at the beginning of the layout, and I'm setting the position every tick.

    2. I'm only syncing 2 sprites and 1 instance variable from one of those sprites. To get my movement, I am using the "setbit" broadcast message way similar to the real-time example given by C2. There's not a whole lot going on in my game, yet the lag is ~600-1000 ms (I'm assuming you multiply peer latency by round(PeerLateencty*1,000?). The jump from the platform seems to vary in height when the peer jumps, as well, and the peer doesn't feel as smooth as the host (obviously). Has anyone else experienced this? Is it because of the wss server I'm using?

    3. The way I'm testing this game is by opening chrome, run the build, open 2 new tabs and run the build again (it opens 2 instances total of the game that one can host and the other can connect as a peer). Is this a poor representation of what I can expect, or should I be testing it a different way?

    4. I know the host has to send the peer all the information, but is there an easy way to let the peer send information to the host and then just update the position of the peer on the host machine instead (so for both the host and the peer, the other player will look a little laggy, but you'll be able to play fine on your own)

    5. The main question, and this is a big one - can C2 handle a real-time multiplayer game in its current state? (node-webkit export)

  • Bump, i need to know too!

  • use socket.io plugin

  • I'd love to hear the thoughts on this as well!

    Particularly the jumping; I'm having similar troubles. I also use the multiple tabs preview system. When I've tried it on multiple computers, syncing does vary more.

  • From my experience with the plugin so far, I can only confirm that either the plugin is coded poorly (which I doubt) or WebRTC is currently not able to handle high precision syncing over the internet.

    However I also noticed that syncing with the Lan mode activated is way better than the Internet mode, but as the manual says: [quote:2qu0sqyg]LAN mode should never be used for Internet games - it is intended for networks where bandwidth is effectively unlimited and latency effectively zero, which is typically only the case with local area networks, and taking advantage of this can improve gameplay quality.

  • The good news is that Yes, you can do a multiplayer game with C2 in real-time that works really well! The bad news is the tutorials are unfortunately the wrong way to go about it. Syncing ANYTHING seems to be a giant pain. I've had much better luck sending messages back and forth and updating positions for each player instead of sending the data to the host and resending it back.

    Something like this:

    On up Arrow down
    If Player.up_pressed = 0
    
    Set Player.up_pressed to 1
    Broadcast message "up arrow"
    
    On up arrow released
    Set Player.up_pressed to 0
    Broadcast message "up arrow off"[/code:1ji0osta]
    
    You then instead of "simulate jump" on up arrow, you check if the variable = 1, and then simulate jump.
    
    Obviously it's much more difficult from there, but with this idea both players play on their own game and the other character's position is the one being updated (instead of sending back and forth every tick).  Not to mention it's only sending messages on keystrokes instead of every tick which is MUCH less intense and should create much less lag.
  • The good news is that Yes, you can do a multiplayer game with C2 in real-time that works really well! The bad news is the tutorials are unfortunately the wrong way to go about it. Syncing ANYTHING seems to be a giant pain. I've had much better luck sending messages back and forth and updating positions for each player instead of sending the data to the host and resending it back.

    ...

    Interesting method of handling multiplayer games, I would like to hear a statement from Ashley about this method and the high precision problems of the multiplayer plugin (used with the Internet mode as profile).

  • ome6a1717's method won't work: both the runtime and network latency are non-deterministic, so only sending inputs will cause the games to diverge until both sides are seeing something completely different. Multiplayer programming is exceptionally difficult, you should really use the built-in syncing features, which have carefully tuned redundancy and compensation features that can adaptively handle things like changing average latency and latency variance, high packet loss and packets arriving in the wrong order, while keeping synced object movement smooth and very close to the position on the host. If you think you can just send a few messages and get a similar system, you are severely underestimating the technology behind the Multiplayer plugin.

    If you run two tabs on the same machine, you should easily see <5ms latency between them. A poor quality long distance link from e.g. UK to Australia could be around ~500ms. So if you're seeing 600ms+ on the same machine, that indicates some kind of fault. The latency is 100% to do with the network connection, WebRTC won't add more than a few milliseconds. I did extensive testing of the feature at the time, and even long-distance games worked well with the multiplayer engine's features for compensating poor quality connections.

  • ome6a1717's method won't work: both the runtime and network latency are non-deterministic, so only sending inputs will cause the games to diverge until both sides are seeing something completely different. Multiplayer programming is exceptionally difficult, you should really use the built-in syncing features, which have carefully tuned redundancy and compensation features that can adaptively handle things like changing average latency and latency variance, high packet loss and packets arriving in the wrong order, while keeping synced object movement smooth and very close to the position on the host. If you think you can just send a few messages and get a similar system, you are severely underestimating the technology behind the Multiplayer plugin.

    If you run two tabs on the same machine, you should easily see <5ms latency between them. A poor quality long distance link from e.g. UK to Australia could be around ~500ms. So if you're seeing 600ms+ on the same machine, that indicates some kind of fault. The latency is 100% to do with the network connection, WebRTC won't add more than a few milliseconds. I did extensive testing of the feature at the time, and even long-distance games worked well with the multiplayer engine's features for compensating poor quality connections.

    Ashley Didn't expect you to respond so quick, thanks for clearing that up!

  • Ashley

    Every time the keys are released, I'm also re-syncing the position of the characters (so if the lag is bad, it'll look like the other character is jumping around, but you'll still be able to play fine). In theory, this should solve that dilema, no?

    Using sync with 2 tabs on the same machine is completely unplayable on my end. Anything pinned to a sync'd object is unbelievably behind the object it's pinned to, so if you're using a collision box sprite AND a sprite for the animations, I don't see any way to make them always line up (similar to if you pin something to an already pinned object: it will always be a bit behind)

  • Even if you occasionally send the position, you're still missing 90% of the multiplayer object's features. It can do things like smoothly correct the position over time so you never see the object jump if a correction is made.

    I'm not sure why two tabs would have such a high latency between them - are both tabs open as their own windows or are you leaving one in the background? If you background a tab, it will basically go to sleep and stop responding to messages, which could explain the ~1s latency. All local testing should be done with both windows open.

  • Ashley

    I don't think it's necessarily latency testing with 2 tabs, it's just the fact that I'm trying to set the position of the player animation sprite to the player collision box sprite and it's not 100% (so it looks like it's lagging 500 ms behind).

    We're just worried that if there is a bit of lag on the hosts end, the peer basically can't play very well. Our game in particular is more important that each player feels literally no lag in their character (it's co-op instead of adversarial). I completely understand where you're coming from, though. We're just not 100% sure on how to implement the sync correctly.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ashley

    I don't think it's necessarily latency testing with 2 tabs, it's just the fact that I'm trying to set the position of the player animation sprite to the player collision box sprite and it's not 100% (so it looks like it's lagging 500 ms behind).

    We're just worried that if there is a bit of lag on the hosts end, the peer basically can't play very well. Our game in particular is more important that each player feels literally no lag in their character (it's co-op instead of adversarial). I completely understand where you're coming from, though. We're just not 100% sure on how to implement the sync correctly.

    For me this sounds a bit like a "suggestion" to sync the objects position and animations (including frames).

    Note that I'm not suggesting a system like that, since the workaround with synced instance variables works OK, but Ashley you can be sure that a lot of us would appreciate a built in system like that for sure.

  • Have you actually made a measurement or are you guessing it's 500ms? People have guessed wrong before, assuming what is really a ~50ms delay is actually much longer. The multiplayer engine adds a short delay (80ms IIRC) for buffering purposes so maybe you're just seeing that?

  • Ashley

    I'm just guessing at that number - what do you mulitply the Multiplayer.Latency by to get the exact number of milliseconds?

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