2

I am creating a multiplayer drag racing game and have difficulties mixing extrapolation and interpolation. To save network bandwidth i am getting information from the opponent only on his button press, which is:

car->speed = newSpeed;
car->distanceReached = newDistance;
car->currentForce = newForce;

And i extrapolate the rest until the next update from opponent. On player update, extrapolation kicks in:

//Find new acceleration, frictionForce and mass being constants.
car->acceleration = (car->currentForce - car->frictionForce) / car->mass;

//Calculate new velocity.
car->speed += car->acceleration * dTime;

//Reduce force.
car->currentForce -= car->friction * dTime;
if(car->currentForce < 0)
    car->currentForce = 0;

//Update distance reached
car->distanceReached += car->speed;

So we got update from opponent - car starts moving until force is equal 0. This seems to be working fine. What is not - when update is received in the middle of extrapolation, i am setting new position directly as seen before and car jumps to adjust to the "real" position. So the question is - how to incorporate interpolation in this situation for car not to jump and not to ruin already running extrapolation?

1 Answers1

1

First of all, make sure you using fixed timestep, instead of variable one. Also adding an extra field of sending time to your messages will probably make things easier, since that way you can tell when the message arrived how many frames is the local game ahead of message sending time.

Ali1S232
  • 8,687
  • 2
  • 40
  • 59
  • Hi, i appreciate your quick replay, but i am not sure about timestep - i am using dtime to make it frame rate independent, so what you are suggesting is to have separate time constant instead of that? Could you explain why?

    EDIT: I think i understand - to have constant timestep, because by sending it to opponent it will know how many frames i am behind as you suggested, but how to make it frame rate independant then?

    – Marius Kurgonas Apr 24 '14 at 08:28
  • about fixed time step, take a look at http://gafferongames.com/game-physics/fix-your-timestep/ or http://gamedev.stackexchange.com/questions/1589/fixed-time-step-vs-variable-time-step. I'm not sure if I could explain better, but if you still had problems understanding them, I'll be more than glad to help you out. – Ali1S232 Apr 24 '14 at 13:51