Synchronization in multiplayer pool game

I am creating multiplayer version of finished pool game which is only single player.
I am exchanging between players only hit ball vectors. So physics is simulated on separate machines, because of it sometimes balls go in different directions for each player.
As I understand it has to do with FPS and delta time…
Is there any way to synchronize that simulated psychics, so it’s same on different devices?

Are you using websockets? If so, you might need to calculate the physics server-side, broadcast the balls’ position and vector to all players every few ~200 milliseconds, letting the individual players’ devices tween the positions in between broadcasts for smooth 60FPS animations.

You see this method being used in lots of FPS multiplayer games: The server is in charge of maintaining all player states to avoid cheating. The server broadcasts the players’ positions and key attributes very frequently, but relies on each device to animate in between broadcasts. If you are experiencing lag, you’ll see your enemies “popping” into place as you receive the updated positions (this occurs because all states are calculated server-side, not in your machine).

Yes, I am using NodeJS.
So there is no way to have same physics on two seperate devices without server-side shysics?

You could calculate physics on the client side, but it’ll lead to inconsistencies. If you’re performing your calculations every requestAnimationFrame(), you run the risk that Player1 is rendering at 60FPS and Player2 is at 45FPS. This will mean that wall bounces and ball impacts will happen slightly differently on each client, and all the ball positions will be different as early as the first break.

Alternatively, if you make one player in charge of calculating the “real” positions, and broadcast these to other players, this player could grind the game to a halt by switching tabs, which will slow down the framerate (see here for a discussion on how browsers limit framerate when switching tabs).

The upside is that you won’t need a full-fledged physics engine for a pool game. You could perform the calculations in 2D space with circles, since pool balls don’t move in the y-axis anyway.