Multiplayer, Lag, and C2

Discussion and feedback on Construct 2

Post » Tue Dec 29, 2015 7:31 pm

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)
B
27
S
5
Posts: 472
Reputation: 2,502

Post » Mon Jan 11, 2016 4:21 pm

Bump, i need to know too!
B
6
S
2
Posts: 46
Reputation: 769

Post » Mon Jan 11, 2016 4:41 pm

use socket.io plugin
B
16
S
6
Posts: 243
Reputation: 1,755

Post » Mon Jan 11, 2016 4:42 pm

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.
B
14
S
3
G
3
Posts: 55
Reputation: 2,451

Post » Mon Jan 11, 2016 7:40 pm

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:
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.
ImageImageImageImage
B
48
S
16
G
71
Posts: 603
Reputation: 40,156

Post » Mon Jan 11, 2016 9:01 pm

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:

Code: Select all
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"


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.
B
27
S
5
Posts: 472
Reputation: 2,502

Post » Mon Jan 11, 2016 9:07 pm

ome6a1717 wrote: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).
ImageImageImageImage
B
48
S
16
G
71
Posts: 603
Reputation: 40,156

Post » Mon Jan 11, 2016 11:53 pm

@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.
Scirra Founder
B
378
S
220
G
84
Posts: 23,871
Reputation: 188,157

Post » Tue Jan 12, 2016 12:01 am

Ashley wrote:@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! ;)
ImageImageImageImage
B
48
S
16
G
71
Posts: 603
Reputation: 40,156

Post » Tue Jan 12, 2016 2:13 am

@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)
B
27
S
5
Posts: 472
Reputation: 2,502

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 1 guest