I read several articles on networking before taking on this project. I made a client/server game in pygame with sockets and figured I could do the same in Unity3D. I opted for UDP protocol with my own framework on top mostly for the challenge, I am fully aware that the very fact I am using UDP could be the cause of this problem… But I have the feeling it is more Unity Physics Engine related.
What I have:
After messing around for a while, I got a server client going with server authority, and client prediction. Simply put it goes like this: GetInput is called from fixed update, which gets current input, updates the clientside player, logs the new local player position, and processes into a string of keypress booleans, and sends to the server with the time it was processed. The server applies this input to the player on the server, then gets the position after it’s applied and sends it back with the same time. This is compared to the local player’s log, if it’s the same, we did everything correctly and nothing needs to be done. If different, we take the servers position, then apply any inputs received since that update to bring us back to the present.
I originally tested client side prediction with server authority using transform.position. It worked fine. It was in sync, and if a packet was lost or something went wrong, then it would update back to the server position and then apply input from there. Generally speaking, it was responsive and stable. That was until I switched over to RigidBody. I am now using rigidbody.position, and moving the rigidbody with rigidbody.velocity… And for some reason the updates are now always out of sync, until the player stands still. Is this because the rigid body takes a frame to update after its values are set? Could someone explain to me how Rigidbody updates and why this discontinuity could be happening? Feel free to ask for any other information.