1

I'm trying to implement entity interpolation into my game. The structure is as follows:

  1. Send the keypress states from the client to the server
  2. Process the inputs and make calculations based on them
  3. Send the state back to the client
  4. On the clients end, store the previous state into a variable, then store the new state into a different variable
  5. Interpolate between the the old state and the new state

However, I'm still getting jittering motion, and the interpolation seems to have no effect. Is this the correct method to interpolate entities, or should I go about this a different way?

//Client receiving data

socket.on('data', function (data) {
  old_data = current_data;
  current_data = data;
});
//Drawing the data using interpolation
for (var i = 0; i < current_data.length; i++) {
    fill(200);
    rect(current_data[i].x, current_data[i].y, 50, 50);
    var nx = lerp(old_data[i].x, current_data[i].x, 0.01);
    var ny = lerp(old_data[i].y, current_data[i].y, 0.01);
    //server updated player
    fill(33, 93, 10);
    rect(nx, ny, 50, 50);
}
Battlesquid
  • 111
  • 3

0 Answers0