Smoothing Player movement using TCP

Started by
4 comments, last by ApochPiQ 12 years, 9 months ago
As is stands right now, the client is in Flash, and can only accept TCP packets.
The game itself is a side scroller (think castlevania).
The problem I'm having is smoothing network characters.
I wanted to try to minimize the movement lag, but I'm having issues.

The big one is the inability to get a good synchronized time stamp.
I've tried using the principles behind NTP, assuming that the transmission lag is identical both ways.
The problem is, when I ran the algorithm updating every second to test it, it failed badly. Presumably due to TCP resending and all that jazz I would get some wild variables, and the number was constantly changing... the offset of the timestamps should not be constantly changing.
The inability to get a timestamp made things jittery, is there another way to go about this? I've been doing a lot of research and most things I'm finding are in regards to UDP.

Anybody got a direction to point me? would be appreciated.
Advertisement
What do you need a shared timestamp for? Generally there is one point of authority that tells everyone what timestamp they're on, and the clients compensate accordingly. Since this is a one-direction operation, there's no need to compensate for connection latency in the timestamp itself.

Granted, this introduces alternative issues (like clients perceiving the simulation to be in different states) but at least those problems have solutions. Two-Generals type problems like NTP/synced-timestamp are unsolvable even in principle.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

What I was doing, which I'm starting to see the flaws in now, is handle most of the physics on the player side, then just do some verification on the server to make sure it was a valid move.
What I need to do instead is have all the positional logic handled on the server, and then send it to the player.
I can run the calculations simultaneously on the client so they don't feel the lag (since the movement is deterministic), I'm guessing?

Where I got on this path originally was looking at World of Warcraft, and how even when you disconnected you could move around, which if you were just feeding inputs to the server get getting the position wouldn't happen.
So is the trick here to run both in parallel?
A common approach for this is to have the clients extrapolate things about other players (and themselves!) between ticks. This allows for your framerate to exceed your network tick rate, which is a good thing. The client then readjusts what it shows once an authoritative update comes in from the server.

This can be tricky to do right, though, because the simple/obvious approach will lead to a lot of "rubber banding" and teleporting and "I SHOT YOU IN THE HEAD WHY ARE YOU ALIVE RAAAAAGE" type problems. The actual solution depends a lot on the nature of your game simulation and how you want it to work; there are tradeoffs to make, so in the absence of the option to have it all be perfect, lag free, deterministic, and in lockstep on all clients simultaneously... you have to pick a few things to sacrifice :-)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


A common approach for this is to have the clients extrapolate things about other players (and themselves!) between ticks. This allows for your framerate to exceed your network tick rate, which is a good thing. The client then readjusts what it shows once an authoritative update comes in from the server.

This can be tricky to do right, though, because the simple/obvious approach will lead to a lot of "rubber banding" and teleporting and "I SHOT YOU IN THE HEAD WHY ARE YOU ALIVE RAAAAAGE" type problems. The actual solution depends a lot on the nature of your game simulation and how you want it to work; there are tradeoffs to make, so in the absence of the option to have it all be perfect, lag free, deterministic, and in lockstep on all clients simultaneously... you have to pick a few things to sacrifice :-)


Thanks for your help, it's one thing to read all this in articles, but its helpful to have somebody lay it out in context, I really appreciate it!
In my case, I have 2d platforming, should I have the controls sent to the server, the position calculated then the player would get the position back, and extrapolate the current position from the previous location/velocity/acceleration, with hopefully minimal correction from the server?
In this case I would still need to keep at least a simplified version of collision detection to keep extrapolations out side of the walls. Using this method and TCP I should be able to still get fluid controls in your opinion?
I'm not asking for a guarantee or anything, :P just a point in the right direction.
Sounds like a pretty reasonable approach to me.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement