0
\$\begingroup\$

I am creating a networked game and having issues with keeping positions synced between multiple clients.

Essentially what I have happening is one client's movement to replaying on another routed through as server. Every 10 steps taken on one client is then sent to the second to be replayed.

The issue is, the actual process of moving from beginning to end starts to fall behind on the second client. Initially I believed it to be a network issue, but on further inspection the packets are coming in fast enough. The player walking is also never delayed. I do have a fixed timestep set at 50 FPS. If I am moving from points A, B, C, D the distances are the same, the velocity is the same. The movement falls behind more and more the further time progresses.

Here is an example:

enter image description here

The red squares are the movement positions received from network, to be used by the client to replay the movement and interpolate. The player is currently in the progress of playing all of the positions received (right to left). This is an example taken about 30 seconds from start of movement. At the start the player keeps up, generally about 1 update behind. It never stops or stutters, velocity never changes, but yet it falls behind, very significantly. The issue continues until the player stops and it reaches the stopped position.

My question would be, why would this be happening? And is there a possible solution?

I've had an idea of artificially increasing the velocity of the entity to catch up, but it seems more of a copout and perhaps unrealistic for one client to see random accelerations.

\$\endgroup\$
3
  • \$\begingroup\$ How is it possible for the velocity to remain constant and yet the object falls behind? Is that constant velocity received lower than the one you sent? Ot is your method of calculating the velocity potentially reporting a misleading number? Try showing us a sample of your netcode for sending/receiving/interpolating updates, so we can help spot the bug. \$\endgroup\$
    – DMGregory
    Jun 6 at 11:27
  • \$\begingroup\$ That's the problem. I have verified the velocity is the same between both clients. Distance is calculated by velocity * (1/50) (the fixed time step). Verified that distances are the same when replayed on the other client. It is a constant velocity from start to finish. Essentially when I get the position packet, it gets put into a list of 'positions to travel' for that entity, and then added to a global walking manager that ticks all moving entities at a fixed timestep. I've been working on trying to trim down the whole game to a small example for testing but it is going to take some time. \$\endgroup\$
    – Charlie
    Jun 6 at 18:38
  • \$\begingroup\$ Hmm... are your positions timestamped? Is it possible your walking manager is falling out of step, walking to position x at tick y, when really that destination was supposed to be reached at tick y - epsilon? \$\endgroup\$
    – DMGregory
    Jun 6 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.