mercoledì 9 novembre 2016

Day 186: Prediction model

Right now the engine was setting the position of a network object only when receiving a packet. This imply snappy objects and/or sending a huge amount of packets. To solve this I'm now keeping track of previous data, and then interpolate to predict results.
To do so I created a struct for each network object which holds the last two positions, velocities, accelerations and even the last jerk (actually only the last value of each pair is needed, but two positions are required to calculate one velocity and so on).
So when a packet is received these values are updated accordingly, and then in the update method the predicted position is guessed.
Right now I only implemented linear interpolation (X = pos + time * vel), and it works, so I assume the same for the other models. I'll test them at the end because right now I don't have a scene that simulates acceleration and jerk and I don't want to lose time implementing it at this stage.
The main remaining problem is that when a new packet is received, the object snaps to the correct position, and in case the prediction was not accurate that's very noticeable. The solution is extrapolation, which is an averaged interpolations between the old predicted position and the new predicted position, which should grant a smooth transition. I'll try implementing it tomorrow.

Nessun commento:

Posta un commento