Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
Add a random fudge factor somewhere, with a very small tolerance? –  Shotgun Ninja Feb 15 '13 at 6:31
2  
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? –  ClassicThunder Feb 15 '13 at 19:39
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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