Lag compensation

Hello guys!

So I am making a Multiplayer FPS and already implemented some techniques that are needed.

What I have is:
-Interpolation on remote clients
-Authoritative Movement with Movement prediciton

So there’s only a third technique missing: Lag compensation.

I thought about it a long time and red somewhere that PhysX has a function to create reckoning scenes. Unfortunately this isnt possible with Unity.
So I thought I’d do it myself.

My idea would be to keep the last 20 positions/rotations of the object just like in the interpolation. The bullets itself will have a script which does 3 things:
-rollback the scene depending on the latency of the player at the moment the bullet has been shot
-test raycast/spherecast against all players
-rollback the scene again to current state

What do you think about this approach?
I haven’t been able to find any other solution to this than doing it manually. Furthermore it’s sorta limiting because it only allows for raycasts and spherecasts.

Hopefully someone can answer this question!

Thank you in advance
Flo

Considering this
your idea is pretty good, though limiting as you stated.
The only thing i could think of right now would be to have instances of relevant objects for each player with a different layer so they dont interact with each other but every object of the same layer/player respectivly. So kinda like a ghost scene for every player.
Dont know if i made myself clear :stuck_out_tongue:

Though i think this is complicated to implement and relativly server-killing :smile:

I stumbled across this thread, and though I cannot contribute much, I am quite curious.

Above, you’re mentioning the two techniques:

  • Interpolation on remote clients
  • Authoritative Movement with Movement prediction

Though this may go off topic: Are there any good tutorials explaining these two? Sounds to me like some important things to learn about, so I’d be glad about a general direction. Thanks!

Those first two things are easy… Unfortunately, depending on how well you want the third part to work, you may have to completely change your way of looking at things and the structure of your code.

You can also use SweepTest and OverlapSphere to check for collisions. And I seem to remember reading in another thread that SphereCast is inherently unreliable for this purpose, though you may want to do some searching on that.

And you’ll definitely have to do this yourself. Depending on the amount of lag / time flux / physics consistency you find acceptable, a circular buffer of past states to test bullets against may be good enough for your needs. Or you may realize that you have a ton of work to do and will have to rewrite a lot of code to achieve smooth, lag-compensated/minimized, packet transit time / packet loss tolerant gameplay and to work around the limitations of the available physics API.

But you’re on the right track, and depending on the physics of your game, may not necessarily need much more than what you’re already trying to do.

P.S. You probably know this, but for others in the thread, the generally used term for this type of lag-compensation is “Rewind and Replay” physics / networking. You “Rewind” to a past state on receiving player inputs, and “Replay” from that state to the present. Googling for those terms should turn up a lot of good info. Everything on GafferOnGames and the Valve / Source Networking Model papers are also considered mandatory reading.