Multiplayer, Lag Compensation

0 favourites
From the Asset Store
The official Scirra Multiplayer Signalling Server for helping peers find and connect to each other
  • OK, so I am really trying to wrap my head around Lag Compensation in Multiplayer.

    I'm hoping someone on the forums with a good handle on this can shed some light on it.

    So I created a 2 player Arkanoid type game, here is a screen shot to give you an idea:

    Everything works great, except many times the peer will think he hits the ball, but misses it. Why? Because of lag.

    Now in the Ghost Shooter MP Tutorials (MP Tutorial 4) the way Ashley does lag compensation makes sense. The firing of a bullet is instantaneous, there is no movement too it. However, in my case there are bouncing balls that are moving. Maybe it's the same thing as. I just can't figure out how it's the same.

    What would be a way to approach this? My brain is really struggling on this.

    Should I be checking on the ball overlapping the paddle instead and then forcing the bounce action? Should I have an invisible sprite that is on the same X path as the paddle and when the ball collides with that, check for a lag compensated value of the paddle.x to see it was in the right place?

    Thanks all.

  • Might I ask how you determine ball movement on peer end ?

  • Bullet Behavior, from the host side.

    I'm happy to share the Capx if you think it would help.

  • First off, I am not sure the lag compensate mechanic is applicable to this situation.

    It seems to me the required mechanic here relies on knowing where a paddle/ball might be, in stead of having to know where it was.

    But, seeing as there is a level of predictive-ness involved in the plugin, it might apply.

    I have not made a mechanic like this yet, but I would start by trying:

    if the ball passes a certain Y , on either end where it crosses a line where it 'could' interact with a peer's paddle, I would perform a quick lag compensated X,Y on the peer's paddle, check for collision with the ball, then return paddle to original position.

    Remember, only the host can perform the lag compensate re-positioning. So if the host deemed it a collision, it will perform the actual collision.

    Right after, you replace the paddle back to its original position, but it will have performed the bounce if that is already in the host mechanics. (and if it really works )

    I always envision the lag compensate test as a method to determine a connected users position (either host or peer), a moment in the past based on the lag time from a peer(!not host).

  • I'll give that a shot, thank you.

    Any chance you can explain a bit better what movingPeerID and fromPeerID are?

    LagCompensateX(movingPeerID, fromPeerID)

    Would movingPeerID be the paddle and fromPeerID be the ball in my case?

  • The moving peer id would be the peers paddle, and seeing how the host needs to determine when/where, the frompeerid would be the host.

    EDIT: this is a bit of a problem, as that would rely on knowing where something was.

    This makes me think it will not work.

  • I'll give it a try. You would think doing something as simple as a pong type interface, shouldn't be too hard. But even with the pong example, you can see the issue as it has no lag compensation implemented.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • OK, I added a sprite box and then added this code. Also on connection of peer I am simulating a latency (default settings). I didn't seem to make a difference. Peer paddle still misses when it shouldn't.

    New code in red.

  • Ah, you missed the concept here:

    events I proposed should look like:

    example for player at the top of screen, Lets call this paddle peerA

    event:

    Ball.Y < 50

    -subevent: PeerA.peerid <> multiplayer.hostid

    -action: set oldx to peerA.x

    -action: peerA set X to lagcompensateX(PeerA.peerid, multiplayer.hostid)

    --subevent: Ball is overlapping paddle

    --subevent: peerA set x to oldx

  • I'll give that a shot.

    What does <> mean?

    Thanks for the help!

  • I'll give that a shot.

    What does <> mean?

    Thanks for the help!

    Its the written expression equivalent of "does not equal" (less or more)

  • OK, that's what I thought. I'm used to !=, the C# in me .

    Thanks again, trying it now.

  • It might be better, but there are still misses.

    Maybe the multiplayer isn't really designed for something like this? Maybe I will stick with doing a turn based game with it.

    I'm attaching the capx here in case anyone wants to play with it. Another problem is on the peer side, all of the block will disappear and come back randomly.

    https://www.dropbox.com/s/6fiuxqhrg3vxs ... .capx?dl=0

    Sorry for the messy code, I was bouncing ideas around. There is a simulated latency action in there, so if you try this over the net, make sure to remove it.

    Appreciate the help, and if I figure anything else I will post here.

  • try : but I will make same game too, card game multiplayer

  • The Multiplayer plugin was too hard for me to grasp especially with these kind of issues, so i switched to using Photon cloud for multiplayer instead. Worked a lot better and much more comprehensible, did you try it out?

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