- Home /
Unet Rigidbody Sync on Client
Hello all, thanks for reading this.
I'm trying to make a multiplayer game with Unet ( again, not my first try ).
Basically what i'm trying to do, is making a player push a ball, using only rigidbodys for now (rigidbody2D)
On the host, it's working fine, but on the client, the ball is going back and forth against the player, as if the ball were stuck to the player. I don't think it's a classic sync issue per se, because, on the client, the host player is well synchronized, and the ball too as long as i dont touch it on the client.
I've tried multiple plugins ( Forge, NST ... ) that didn't help me with this ( actually it was worse in certain cases ). I also tried to disable the rigidbody on the client, and only sync the transform of the ball, but it didn't work. Finally, I tried to disable the LocalPlayerAuthority ( this seems to be the issue ), and send commands from the client to move the player on the server. This has been the "best" solution so far, but my player is stuttering in its movement, and often touch the ball on the client although there's a space between it and the ball ( i'm guessing latency ).
I really don't know what more to do, except coding my own network environnement, and I'm not even sure that will fix these issue.
Do you have any idea? Is UNET really usable? I've seen a lot a post from 2016, but not so many in the recent months.
Thanks
Answer by MGijs · May 04, 2018 at 08:20 AM
I ran into a similar problem when creating a fast-paced multiplayer game that was using rigidbodies, here are some tips that helped me to improve my game:
Only run physics on the server, I separated the game object that had force applied on it into a physics object and a visual object
The server physics object sets the position of the visual object and using a syncvar I synced the position of the visual object on all clients
When moving the players rigidbody I send the requested position as command to the server, then i call a rpc method to set the position; rigidBody2d.MovePosition(position)
There is also a plugin which allows you to easily sync rigidbodies and transforms using interpolation and extrapolation although this might be difficult to tweak using fast-paced gameplay but you can have a look at it nonetheless: https://assetstore.unity.com/packages/tools/network/smooth-sync-96925
Hope this will help you to improve your game
Answer by VincentR · May 04, 2018 at 01:23 PM
Hello, Thanks for your answer.
Indeed that's basically what i've been doing so far, and what works the "best" ( i dont think it's perfect )
I have questions though, if you can answer them :
2 => Why use SyncVar instead of a NetworkTransform ? Is it faster? Network Transform has an interpolation system that makes things smoother on the client.
I looked at SmoothSync but I dont really want to spend money in something i'm not sure will be working in my project. do you have it? did it help you in yout project?