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