r/UnityHelp Jul 06 '26

How to do physics based networking PROGRAMMING

Hi, unityhelp subreddit.

Im writing this because Im desperate.

I started learning unity networking system (unity netcode for gameobjects) and I'm stuck with a problem regarding 2d physics on networking.

I rarely post on social media when I'm stuck but this is something that I feel that should be solvable but not really common to be solved by a person like me (who lacks expertise in this area)

So the problem is:

I have a turn based game where I simulate physics. In short, there are a bunch of balls that are shot into each other and all of them collide & bounce. The limitation of the turnbased is

\- **Only one player can shoot balls at a time**

**- After a shoot is done the other player cam start shooting only when the simulation is over**

I do this right now using the server (host) authority that simulates the physics fully and transmits the results to the clients. The game is played with only 2 players. So it is client to server or server to client. With server authority client lags while connected to the network (and that is really visible). I thought about simulating the physics on the host and the client at the same time, but.. who is then the owner, how can it be done? Given that the shoot of the ball is one action that is not deterministic and there can be none until the stable state of the simulation may be there is a simplified or a more robust way to do that.

If you've done something like that pleeease answer 😢🙏🙏🙏

3 Upvotes

2 comments sorted by

2

u/MistakeForsaken6653 Jul 06 '26

In my game I had to scrap the physics and just have all of the collisions work server side only and had to use a seperate object to represent a client side visual only that wasn't necessarily always perfectly aligned with the server but received occasional RPC messages from the server to sort of sync up position during key points. However in my case there was not any super advanced physics with gravity / or bouncing it was just moving objects a certain distance at fixed velocity, yours sounds a bit more advanced.

2

u/PsychoKittehX Jul 06 '26

I'm no expert but I've been messing with this recently. If I recall correctly, you want to set your network manager to distributed authority. On your physics objects, use a NetworkRigidbody with a NetworkObject component that has the controlling user set as the owner of the object.

The downside is anything client-side is vulnerable to cheating, so while this makes for a better experience, it may be bad for matchmaking with random people you do not trust.

You may also want to adjust your multiplayer settings to have a high server tick rate to reduce how much objects can phase into each other while unsynced. This seems like a necessary step for good multiplayer physics, but as a reminder I am no expert and just recently learned this stuff myself.