Lag compensation is inaccurate

I have been trying to implement lag compensation into my FPS project and my current method is:

  1. I save all the players’ positions every 0.1s. (i delete the oldest saves after around 1 second)
  2. Each client sends their ping to the server every 0.4s. (i delete the oldest saves after around 6 seconds)
  3. I do hit detection on the client and send a remote event whenever a player’s bullet hits something.
  4. The server script receives the remote event and:
  • Calculates the shooter’s ping by accessing his ping table and finding the average of all the saved pings.

  • Does a first interpolation to find the hit player’s server position BEFORE the remote event was received. ( hit time = current time - using shooter’s ping/2).

  • Does a second interpolation which has the goal of finding the position of the target at the time of impact on the shooter’s screen and it is done by doing: hit time - ping/2 (since the shooter’s view is late by half of his/her ping compared to the actual server state). I then end off by positioning a part at this position for visualization. (default color pipe looking part)

Ignore the other cubes in the following images:
(Also you might be wondering what i’m hitting, well my friend doesn’t want to be in the image so he moved out of the way, but take into account that when i fired, he was at the cursor and moving to the left of my screen.)


this is an inaccurate position rewind (see how the pipe is to the left of the cursor?)


this is an accurate position rewind

So my problem in the end is just that it doesn’t always rewind to the correct position, but I’m not sure what causes that. My guess is that taking the average ping of the shooter isn’t always accurate. However, do I make the players send their ping more frequently or less frequently? And how many saved pings do I use to calculate the average ping? Should I take the median instead of the average?

This probably isn’t the answer you’re looking for but in roblox lag compensation is, in my personal experience and opinion, no better than properly setting up client sided hit registration and validating it on the server
The work and accuracy required to pull off lag compensation isn’t really realistic when there’s another easier solution, especially considering the fact that roblox doesn’t particularly make it easy to make complicated high accuracy lag compensation systems found in many high end games

I understand that there is definitely risk in doing this on the client, but my proposed solution should be as safe as server sided hit detection while being leagues more accurate
This solution is:
Client decides if a hit is valid or not, then tells server what it hit, where their character is, and where the target is
Server does basic rate checks, checks if the starting and ending points are within a certain range of the target, potentially based on ping but also potentially based on some set value, say 10 studs, if it’s beyond this threshold, invalidate the hit (this step might seem unnecessary but it increases the accuracy around sharp corners and close quarters much higher, and realistically the only exploiting danger it adds is the ability to shoot around corners with a bot very quickly which would be possible with a properly made server sided lag compensation system anyways)
Next, raycast on the server for non-moving static objects ONLY between the client provided start-end positions, if it hits a non moving object, invalidate the hit

With these three simple steps, it becomes just about as safe as a server sided hit detection system, with the only further consideration being the other considerations I said before and aimbot (which is possible with server sided hit detection too, with a similar exploiter-side lag compensation)

I believe this is the ideal system, given what we are given right now as developers
This is just my personal opinion however

3 Likes

Thanks for the suggestion, but I’m not sure I understand what you mean by “starting and ending points”.

Like where the bullet starts and ends, so the character and target character
If youre doing bullet travel times itd be a bit different but