Multiplayer Pong: synchronizing ball & paddle

Get help using Construct 2

Post » Mon Mar 17, 2014 3:09 pm

Hello fellas,

following question: what is the best way to implement/synchronize the ball in the pong using C2 multiplayer plugin.

The ball has bullet physics reflecting from solids. Normally on the host everything is displayed correctly, but on the peer sometimes the ball behaves not as expected, I think it's because of position syncing from the host. So the problem here, that the same ball is shared by host and peers and should be synchronized from both sides. Any ideas?
Last edited by xoros on Fri Mar 21, 2014 10:34 am, edited 1 time in total.
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

Post » Mon Mar 17, 2014 4:56 pm

May be I shouldn't use a bullet behavior on the ball, but calculate reflection angle as a synced variable and animate the ball's position manually? Something like lasers are implemented in the multiplayer example?
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

Post » Mon Mar 17, 2014 6:03 pm

Make sure the peer disables any behavior on the ball: 'sync object' will be moving it, and if any other behavior is still enabled it will conflict with the multiplayer movement.
Scirra Founder
B
399
S
236
G
89
Posts: 24,525
Reputation: 195,382

Post » Mon Mar 17, 2014 10:20 pm

Ok, I'll try that.
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

Post » Tue Mar 18, 2014 10:30 am

Unfortunately disabling all behaviors on the peer's side didn't help.

Sometimes the ball doesn't reflect from the paddle or goes through the paddle on the peer's side (like at the moment when the paddle is being moved). I do understand why: the trajectory which was calculated on the host is not 100% in sync with paddle position on the peer side.

I also tried disabling this on the peer side: getbit(Peer.inputs,0)=1 > Peer Simulate 8Direction pressing UP. Which mean the paddle is being moved only by position syncing from the host. In this case everything is displayed correctly, but movement happens with delay.
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

Post » Wed Mar 19, 2014 10:15 pm

Wow really!! I'm working on a similar concept of pong with multiplayer support... (right now its a mess tho) I'm basing it on the chatroom tutorial but I'm having trouble sending the player to his room and keeping the host on his "host room" ... (looong story and there's reasons too) reading a bit more to see if i can fix what i have so far.
[edit]
- to be a bit technical
- I'm attempting to keep the host and the player on separate rooms.
- using a "portal like" action to send the ball to the other player (along with the trajectory angle and position in x)
- it works well in theory I should be only sinc-ing when the ball comes in or goes out. and the marker.
-at least in theory it should work. however I cannot test that theory outside the host room at the moment since my player never gets into his room and crashed the other browser window.
Freefall Bird
B
47
S
9
G
5
Posts: 281
Reputation: 5,803

Post » Wed Mar 19, 2014 11:57 pm

I built it similar to the multiplayer shooter example and it almost works, except of those issues which I mentioned above. Paddles are peers, bullet physics is calculated in the host, peer displays only position change which is broadcasted from the host.
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

Post » Thu Mar 20, 2014 11:29 am

If the ball does not do the same thing it's doing on the host, you're using 'Sync object' incorrectly. You should leave it to move the ball automatically, and not make any attempts to move it with events or behaviors on the peer. The host should do the collision check and make it bounce.
Scirra Founder
B
399
S
236
G
89
Posts: 24,525
Reputation: 195,382

Post » Thu Mar 20, 2014 7:43 pm

The thing is, when the peer only renders data from the host including paddle and ball movement, there's an unpleasant lag in response to the peer's input. If I move the paddle in the peer directly + sending inputs onClientUpdate (e.g. with 8 direction behavior), than I get this synchronization issues. In the shooter example, peer also moves the soldier directly with 8 direction behavior. I don't like how I've expressed myself, but I hope you understand what I mean.
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

Post » Fri Mar 21, 2014 10:32 am

OK, after reading the third MP-tutorial, I think there should be "ball hits paddle" lag compensation, in order to solve the above mentioned issues.
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests