time.deltaTime for multiplayer interpolation issue.

My game is a multiplayer game. (No pause)

Movement of object are synced to server at first second client joined. And later on it’ll not use network connection anymore.

I move objects using time.deltaTime so movement will be exactly same as server.

Issue happen when a client freeze in a frame for seconds then it’s won’t sync each other anymore.

I though time.deltaTime calculate by frame but why this happened and any alternative ways?

I think the UNET (Unity’s networking ) idea would be for you to use SyncVar on the positions of various objects. Each player should handle his own positioning, and the server could handle positioning of various other objects moving in your game.

There are a few tutorials out there for Unity Networking all of them cover using SyncVars. They are actually pretty easy to use and implement. Once you setup a variable correctly, Unity handles all the synchronization. Here is one set of tutorials for a Unity Networking game:

But there are quite a few out there.

Yeah I use UNET in my whole game.
But this case there are too much objects (>200) it’s shouldn’t all done by network.

Time.deltaTime is how long the previous frame took to complete. This will be different for every client and from frame to frame so it shouldn’t be used in a deterministic way.

It sounds like maybe you want a lock-step implementation but it’s hard to say without more information.

You could doing all your movement in FixedUpdate. Its suppose to be for physics, but its a guaranteed amount of time it gets called. I think 50 fps by default… but you could lower that if you needed. Then all your movement will be in sync

Thank you, I’ll try this.
Currently my quick fix by use an interval to sync time. That’s increase little overhead.

Thank you for you answer
Can you explain a little more about what’s lockstep? :slight_smile:

It’s used mainly in strategy games and games with a large number of objects that have to be synchronized across all simulations where it would be impossible or unwise to send that data over the network. Basically, the pipeline goes something like this:

  • Client wants to perform an action (say move a unit). They do the proper input (say right clicking on the ground where they want that unit to move)
  • Right clicking sends a request to the server (Client A wants to move Unit 1 to location XYZ)
  • The server packages that request up and assigns a unique ID to it (say 001). This package is sent to all clients
  • When a client receives the package it puts it on a queue and sends a response back to the server saying “I got package 001”
  • The server keeps track of these responses and when the last client says they got the package the server sends out another message to all clients saying “Process package 001”
  • When the clients receive this message they grab that package off the queue and execute the actual logic behind it

This way, actions aren’t actually executed until all clients have the data they need; so no one client gets ahead or behind in the simulation. There’s a ton of more in-depth information and implementation examples out there. Just google around.

2 Likes