A major issue I am encountering right now is that my physics engine (BEPU) and my network interpolation are conflicting with each other.

The player is a physics object, and so the physics engine updates it every update on the client. When the client receives an authoritative position from the server, it replays the player's commands since the position was sent, and sets a "serverPos" variable in the player controller to that value.

Unfortunately, if a player should be on the other side of a bump in the terrain, the interpolation code will move the player into the terrain, which will cause loop of the player getting pushed back, the interpolation algorithm trying to push the player back in, and so forth until the engine literally explodes and gives me an NaN error.

My interpolation algorithm is extremely simple; each update, I keep track of how far the player has moved, add that to the interpolation target, and subtract away the distance interpolated from the last frame:

Vector3 serverPos;
Vector3 interpolationDistance;

void interpolate()
   serverPos += Position - lastPosition - interpolationDistance; // interpolated distance should not be factored into the target, as it will cause an infinite chain

   Vector3 preInterp = Position;

   Position = Vector3.Smoothstep(Position, serverPos, 0.3f);

   interpolationDistance = Position - preInterp;

Any advice on how to deal with this is greatly appreciated.

  • \$\begingroup\$ Add a random fudge factor somewhere, with a very small tolerance? \$\endgroup\$ – Shotgun Ninja Feb 15 '13 at 6:31
  • 2
    \$\begingroup\$ Is physics on both the server and client necessary? Can you just do physics on the server and resolve an collisions on the client by pushing the object upwards until it is out of the terrain? \$\endgroup\$ – ClassicThunder Feb 15 '13 at 19:39

The problem is who owns the master copy of the data. I saw a similar problem on trial versions of Halo.

Your server updates the master position, and your interpolator believes it. The problem is your collider believes it owns the master copy of the data. That should be updated by the server as well as the interpolator, but when a master copy comes across the wire you should respect the server's version of events.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.