Lag compensation

Hello dev fourm! my group has ran into a problem, we are using cars and when you go fast enough the start lagging all over the place. we figured we would need to make a lag compensation system. The only issue is we don’t know how! any help is appreciated!

2 Likes

Are you guys setting the network ownership of the car to the player driving?

1 Like

Yes, on the players screen there is no lag but the other players see the car behind where the driver sees the car

1 Like

Ah okay, I wasn’t really sure since you didn’t specify that in the original post. Now I fully understand the problem.

So essentially, the issue here is the latency between server changes and the time it takes to reach the client. This results in the clients seeing cars moving in a “laggy” way. The best solution to this would be to use simulated positioning. On the client, you can simulate car movement moving based on various variables such as torque and speed. This would eliminate all latency you are running into - especially at higher movement speeds.

Alternatively, you can try place the car a bit further ahead on the server to reduce latency too. However, this may result in weird behavior at higher speeds.


There is also a feature request that talks about the need for simulated position for cars to ultimately solve the issue at hand.

1 Like

do you think it would be good to send the position from the client to the server then move the car forwards acording to the other players latency?

How could I find players ping?

Nope, that’s not what I’m suggesting. The server should verify the car’s true position and still set things such as torque, speed, etc. The clients should simply simulate and predict vehicle movement to remove the latency you are seeing.

I do not believe this is possible, but it is not necessary for simulating the position of the cars on the client.

you are a genius ok, well thanks for the help

1 Like

So I could look at the inputs of the client on the server and then the server controlls the car

Yes, and the reason this helps is that the server is the man in the middle. Having the server be authoritative halves the latency all other players have.

The client performing an action should respond immediately by starting to turn or accelerate and make any corrections required when the server responds with where the car actually is. To make the best educated guess how much to turn or accelerate before a response is received, you’ll need to calculate the average latency of a round trip using remote functions / events. This immediate response should be slower than a regular turn. Other clients can catch up by increasing the rate of acceleration / turning rate instead of slowing. With the man in the middle in control, the actor slowing down, and the observers speeding up, everyone should see roughly the same thing.

4 Likes

Bump, I found a better solution.

You need to use SetNetworkOwnership, duplicate everyone else’s car models and just keep their PrimaryPart of the original and you can then interpolate using New_Primary_Part.CFrame:Lerp(Old_Primary_Part.CFrame, Alpha).

This solution will help with the cars glitching behind and them acting weirdly while cruising with them at a similar speed, same thing with collisions and it should also remove some weight off the server too.

1 Like