Today I managed to finally fix and complete the interpolation code. I still had many problems, and I was able to fix them all today.
First, I wasn't able to address the lag problem. So today I noticed that there was something wrong... My interpolation was happening between the last predicted position and the position received by the packet, but this doesn't account for the latency.
The code I had was doing the following:
- interpolation to smooth from the last predicted position to the received position
- extrapolation to predict the position in the next frames
And now I replaced it with this code instead:
- extrapolation to calculate the predicted position
- interpolation to smooth from the last predicted position to the predicted position
- extrapolation to predict the position in the next frames
Now everything works fine.
I ran testing with 150ms of lag, and the result is very satisfying: the path is of course imprecise, but smooth. Also, if the prediction is correct (i.e: going in a straight line, or rotate at constant speed) the prediction is perfect even with very high lag.
I also tested the game with every possible bad network condition active, and nothing presented much of a problem (except packet tampering, but that's not really something to worry about).
Nessun commento:
Posta un commento