I'm doing a network implementation of a fast-paced game. I have a puck on bot the server and client side of the simulation. I want to update the client puck position only if they are on the same direction and the server's puck is ahead of the client's puck. If the message comes with a delay and the server's puck is behind client's puck I will keep that way.

So I tried this, which is not working properly and sometimes causes some glitches.

b2Vec2 puckLocal = b2Vec2(puck->GetLinearVelocity().x, puck->GetLinearVelocity().y);
b2Vec2 puckServer = b2Vec2(vx, vy * -1);


float_t dotProduct = puckLocal.x * puckServer.x + puckLocal.y * puckServer.y;

if (dotProduct < .9) {

Is it correct? I have read that if I normalize two vectors, and do the dot product I get their direction. Which -1 means opposite direction, 0 perpendicular and 1 same direction. Is that correct?

What is the best solution when the angles differs a bit? Like the result is .85 which means that they are 30 degrees from each other? Should I interpolate it? Any suggestions on that?

  • \$\begingroup\$ I think the problem happens when they differ a lot in length. Could that be a problem aswell? \$\endgroup\$
    – gmemario
    Oct 18, 2011 at 13:36
  • 1
    \$\begingroup\$ Really, don't go for the 'update if ahead' stuff - it can lead to incorrect results - interpolate the results over a very small time period; just like Counter Strike and most non-RTS games do. \$\endgroup\$ Oct 18, 2011 at 18:50
  • \$\begingroup\$ Am I failing to see other than its context for you, how this relates to networking? Looks like just a vector math question? \$\endgroup\$ Oct 18, 2011 at 22:32

1 Answer 1


What can affect the movement of the puck? Is this pong?

In any case, I would recommend a different synchronization technique. I would send three pieces of information from the server to the client:

  • Position
  • Velocity Magnitude and Direction
  • Time on a shared clock

The shared clock can be done many different ways, and it could depend on the language you are using. A common ways to achieve a shared clock is for the server to use its own system clock, and the client(s) use their own system clock with an offset to the server's clock. To calculate the offset, the server would send its time to the client(s), and the client(s) would take the difference in clocks minus half of the ping time to adjust for network latency.

Note: Network time synchronization is actually quite a deep subject, I have provided a very simple solution that should work over relatively short periods of time like in a networked game. If you're interested, here's some further reading: http://en.wikipedia.org/wiki/Clock_synchronization

By the time the client receives the puck packet, the time at which the event took place should be in the past, and you can interpolate where the puck should be as of right now. If the event is not in the past, you will want to re-adjust the client's clock.

Here is a related post: https://stackoverflow.com/questions/4713582/simple-online-pong-game-network-synchronization


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .