Search Unity

Third Party Photon fusion multiplayer game (laser hockey) with physics

Discussion in 'Multiplayer' started by mahmoudhjz, Mar 29, 2023.

  1. mahmoudhjz

    mahmoudhjz

    Joined:
    Oct 7, 2021
    Posts:
    1
    Hello Everyone,

    We are implementing a laser hockey game that can be played online using photon fusion. We tried using many strategies and flows to try to reach the best solution where the puck/ball collision can be handled properly and the paddle's movement should be smooth. These are our results based on different strategies:

    A) Host/Client game and moving paddle based on input + Physics 3D server mode, it caused a delay in the paddle movement in the client side. As you can see in the video there is a lag and the paddle is always behind the client's input touch point
    Result Video: https://drive.google.com/file/d/11CCTxVK6QzsHTAqu6Oel58JPloqFnzC5/view?usp=share_link

    B) Host/Client game and moving paddle based on input + Physics 3D client prediction, it caused weird behaviors and movements.
    Result Video: https://drive.google.com/file/d/1oGk1m4pLhsd7MYaJcag-sX75hSmzOb48/view?usp=share_link

    C) Shared Mode game and moving each paddle in FixedUpdate on each node + Physics 3D server mode. The paddles move correctly but the physics of collision with the ball is wrong.
    Result Video: https://drive.google.com/file/d/1ddoSrN5zslpAgSIjfPzG0tdkfKplVjje/view?usp=share_link

    D) Shared Mode game and moving each paddle in FixedUpdate on each node + Physics 3D server mode + Eventual Consistency + Area of interest. The paddles move correctly but the physics of collision with the ball is wrong + some ball jittering.
    Result Video: https://drive.google.com/file/d/1gK58tA94zJxPz7qS9mcmEqmExXpJSw9N/view?usp=share_link

    And I attached the snippets of some functions or components.

    I read somewhere to reduce the heavy calculations in onInput so I split it.

    1) I calculate the needed touch point in FixedUpdate based on user input + screen height:

    Fixed Update.PNG

    2) I pass the info collected in onInput:

    OnInput.PNG

    3) I read the passed data in FixedUpdateNetwork and re-calculate the touch point based on new device screen resolution and pass the needed force to the rigidbody:

    Fixed Update Network.PNG

    Finally, The network objects (Ball + Paddle), Ball:
    Ball.PNG

    Paddle:
    Paddle.PNG

    Please advice to know what better we can do to reach something close to real-time simulation.

    Thanks in advance.
     
  2. KuRiXY

    KuRiXY

    Joined:
    Aug 1, 2014
    Posts:
    4
    Looks like some bug in your code. I am using shared mode for something similar with great success.
     
  3. bloodenjoy

    bloodenjoy

    Joined:
    Sep 14, 2017
    Posts:
    1
    you should using com.unity.physics instead unity collider and rigibody