please help with multiplayer and physics (ball)

0 favourites
  • 4 posts
From the Asset Store
Enjoy the powerful simulation with accurate ball physics, build with realistic ball spinning animations
  • Hi everyone...

    I'm trying to make a small multiplayer game. I state that the concepts are all quite clear to me, and this is the fourth multiplayer game I make ...

    different, compared to the others, this uses physics ... and is giving me a bit of trouble that I can't solve ...

    the game is simple: it is a kind of volleyball, two players (one host and the other peer) bounce the ball with each other. the ball has behavior physics. the two players have behavior platform for movement.

    the players and the ball are the synchronized objects, the player has the input values ​​of the client set on the inputs (bit by bit for the left, right and jump controls).

    peer behaviors are not disabled because I use peer input prediction enable.

    given this, here is the problem: the host has the authoritative version of the game, and on the host everything works perfectly, while on the peer, although the movement takes place smoothly due to the input prediction, the collision with the ball by the behavior physics, occurs with lag, effectively making the game unplayable.

    I would like to use lag compensation, but I don't know how to implement it with the physical ball ... do you have any suggestions?

    I am attaching the capx so you can do some testing if you want ... I'm going crazy without finding a solution ...

    P.S. behavior physics I can't remove (I need to experiment to do another, more complex project, based on physics)

    thank you all for your help

    here the capx: drive.google.com/open

    you can test, run it in two different browser windows/tabs

    also Ashley some ideas?

    (sorry for cross-post in Construct 2 > General Discussion also)

  • Wow. Thanks for this question.. I am also making a Multiplayer Physics (Cricket) game.. and although I didn't implement that part yet, I actually did foresee this problem coming! Because with the slightest of lag, the collisions, in my case the exact Bat angle and the trajectory of the ball as seen by non-Host would make no sense.

    The Solution: if ball > scrollx ..then.. Toggle Host and re-Sync objects.

    Only if that existed.. I don't know if this is even possible during the game? Ashley ?

    But for now, I am going ahead with separate screens for batting and bowling, so the users only see their portion of the screen. They don't see how the collision for the other player happened. It will work for you too, but it won't be as fun not seeing "how did the opponent manage to pick that one!".

    Looking forward for better solutions too.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The Solution: if ball > scrollx ..then.. Toggle Host and re-Sync objects.

    Hi Dr.Hasan, thanks for the answer ... but the solution you proposed is wrong for different reasons.

    1. You cannot exchange the host and peer after connection, for technical reasons. Just as you can't change synchronized objects (they are declared before connecting to the signalling server).

    2. The host is the one who has the authoritative version of the game: the whole game (therefore also the physical simulation) happens only on the host. Peers just try to keep up with the best they can.

    3. Surely in some way, taking into account the previous 2 steps, you can still show the view of what happens only on the single players (very simply you could just set the camera). Alternatively you can make a common host and both 2 peer players (but in this way simply double the problem).

    4. Even if you do this you would still have the problem, as you would still see the ball cross the player before he hits it.

    I know what the solution would be, the problem is that, due to the physical engine, I don't think it's feasible.

    The (theoretical) solution consists of:

    a. enable peer input prediction (ok, already done);

    b. send peer inputs to the host (ok, already done);

    c. the host must rewind the peer player to where it was before the lag (feasible);

    d. the host must check the overlap of the ball with the peer player (feasible);

    e. the host must perform the physical simulation taking into account the impact of the ball with the peer player (if any) to the position of the past (I do not think this is feasible);

    f. the host must report the position of the peer player to the present position (feasible).

    the problems are concentrated in the steps d. and e.

    for step d. the host should disable the physics behavior of the peer player, pause (I don't think disabling is correct) the physics behavior for the ball, then start the overlap test;

    for the step e. after the host has verified the overlap, recalculate the physical simulation based on the impact occurred (!), then restart the simulation with the new settings (!), and after a certain period of time (ie after the ball no longer overlaps the player), rehabilitate the physics behavior even for the peer player.

    I believe this is not possible (or at least I don't know how to do it).

    perhaps you can completely ignore the steps d. and e. causing the physical engine to handle the collision with the peer player once it is brought back ... I have not tried, but I think you would get some unreal results from the physical simulation (for example, the player, moved backwards, could launch the ball because it moved quickly towards it).

    the concepts are clear to me, my problem is to put together the physics engine with the multiplayer engine ...

    I hope for some help in this regard, or in an alternative solution that makes sense (taking into consideration that I need to use the physical engine).

    thank you all

  • no idea?

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