Photon fusion multiplayer game (laser hockey) with physics

Options

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:



2) I pass the info collected in onInput:



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:



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


Paddle:


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


Thanks in advance.

Comments

  • WARdd
    WARdd ✭✭
    Options

    I'm assuming you're letting Unity handle the physics here..

    The ball definitely needs a NetworkRigidbody in stead of a NetworkTransform. I'm also pretty sure you want to set interpolation data source to "Predicted" and experiment with how low you can tune the Target Interpolation Delay AND all the Error Correction Settings.

    Shared mode is a bit wonky, in that case you will need to pass control of the ball back and forth between the 2 players so they can correctly handle the physics on their end, which I'm thinking might be annoying to implement, but it might make the most sense for a casual mobile game. Shared mode will always cause trouble if both players can interact with the ball at the same time though.

    Host/Client might be easier but you will need to set up client prediction perfectly, as you may have noticed.

    The main key to prediction is that physical colliders of the puck and ball are seperated from their visuals, which will be under the interpolation target transform. That way Fusion can simulate and re-simulate the physics while keeping the visuals nice and smooth, even if it needs to readjust here and there.

    All in all you should realize there are limitations based on Network latency, Fusion can never know ahead of time what your opponent will do so the visuals will always have to interpolate and correct over time. Ideally you would take into account network latency in the game mechanics themselves. It would help for example if there's a dead-zone in the middle that gives the network some time to square the simulation and get the ball in the right trajectory.