Ball synchronization in multiplayer game?

Hi. I am making a game like haxball. I need to drag and shoot the ball but I have a problem, the ball doesn't act normal for the remote players. On the master client, the ball acts normal, while it acts weird on the remote players' screen. When the master client drags the ball, or shoots, the ball action is exactly how it has to be, but when I try to drag/shoot the ball the ball is weird. When I drag it, it is literally resisting against my player, the ball doesn't want to move, but it moves a bit, then resists again and moves again. I have seen some topics where we need to use something like PRC or something like this but I didn't get how to use it. Also I don't even know what the solution is right now. After days of work, I wanted to ask here finally. What should I do to sync the ball normally? I know lag and undeterministic physics matter but I know in this case I am doing something wrong, and I suppose these thing are not the main problem here. There must be something I haven't applied. So what should I do? Thanks in advance.

Best Answer

  • Tobias
    Tobias admin
    edited September 8 Accepted Answer
    Explaining this here is sadly a bit out of scope as PUN 2 doesn't have the foundation to implement this interaction well. PUN does neither have a tick based engine (so input / reactions are imprecisely timed by definition), nor does it use the send rates I'd recommend for this kind of action.

    You may want to look into Fusion. It has one authoritative client and this controls the physics. Everyone else is sending input and gets the results from the authority. This is a much better architecture for this case.

Answers

  • One player has control of the ball and sends the position updates. Everyone else is just using those updates when they come in and place the ball accordingly.
    If you don't transfer ownership, the ball will act up, when used by anyone but the controller.

    It's actually hard to allow everyone to interact with the ball, which is also physics driven.
    Do players kick/drag the ball at the same time? Fight over it?
  • Actually yes, kind of. Since it is a 2d football game (like haxball) they will fight for the ball. I am stuck at this point for days. I don't know if you know haxball, but you can check it for a minute and then eventually you will get perfectly what I want/ask.

    First I instantiated the ball rather than using it as a scene object, but it had some problems. First, the ball was appearing for the local player only and there was a ball for each client. After that I created a singleton script for 1 ball instance but it did not solve the problem that only the master client had a ball in its screen. The ball has photon view, transform view and rigidbody2d view components. Then I simply converted the ball to a scene object instead of a prefab. Now there is 1 ball but the movement is not perfect for each client. I was reading some topics and the documentation but I really didn't understand what I should do. Can you explain/show me what I have to do?
  • Tobias
    Tobias admin
    edited September 8 Accepted Answer
    Explaining this here is sadly a bit out of scope as PUN 2 doesn't have the foundation to implement this interaction well. PUN does neither have a tick based engine (so input / reactions are imprecisely timed by definition), nor does it use the send rates I'd recommend for this kind of action.

    You may want to look into Fusion. It has one authoritative client and this controls the physics. Everyone else is sending input and gets the results from the authority. This is a much better architecture for this case.
  • How will I implement Fusion? I already created a new app from the dashboard but will it just magically work if I past the new app id or should I do/change something else?
  • Tobias
    Tobias admin
    edited September 9
    You will have to download and import Fusion from our page.
    Then paste the Fusion AppId into the settings and follow the guides on the docs to get started.

    Disclaimer: Fusion is in beta currently. The APIs may still change and the docs are known to be lacking in detail and ease of use. Still, Fusion is a much better choice for this type of game, than PUN 2 is (where problems will show up much later in the development, when you polish synchronization).
  • camouflaged_penguin
    edited September 10
    stumbled upon this. i wanted to create a football game, too but it didn't work. The position of the ball is not transfered accordingly to the other players.

    i tried a few things but couldn't improve the behavior. That said it seems PUN is not the tool i should use to create that kind of game?

    when one player picks up the ball and shoots it. its new position is not seen by the other client or not at the same place.
  • camouflaged_penguin
    edited September 10
    Tobias wrote: »
    One player has control of the ball and sends the position updates. Everyone else is just using those updates when they come in and place the ball accordingly.
    If you don't transfer ownership, the ball will act up, when used by anyone but the controller.

    How to transfer the ownership?
  • ah found it already...
    ok this gets way more complicated than i thought.
  • Tobias
    Tobias admin
    edited September 10
    this gets way more complicated than i thought.
    Yes, this is what I meant by
    It's actually hard to allow everyone to interact with the ball, which is also physics driven.

    It's not that simple. Physics need to run at high framerates and any delay and correction is very annoying and visible. So lag and network variance are hard to hide and the results get pretty unpredictable in many cases. Fusion syncs input to a host and the state back to all players. This is at least a consistent result.
  • camouflaged_penguin
    edited September 10
    So you would recommend Fusion because of its synchronisation. That makes sence. I just hoped i could stay with using Pun but that sounds a bit like a dead end.

    As far as i get you right: Pun is not a fitting tool when i play with mutliple physic Objects that have to be synched for all players at all times.