I'm building an MMO using Node.js, and there are monsters roaming around. I can make them move around on the server using vector variables acceleration, velocity and position.

acceleration = steeringForce / mass;

velocity += acceleration * dTime;

position += velocity * dTime;

Right now I just send the positions over, and tell the players these are the "target positions" of the monsters, and let the monsters move towards the target positions on the client with a speed dependant on the distance of the target position. It works but looks rather strange.

How do I synchronise these properly with the players without looking funny to them, taking into account the server lag?

The problem is that I don't know how to make use of the correct acceleration/velocity values here; right now they just move directly in a straight line to the target position instead of accelerating/braking there properly. How can I implement such behaviour?


1 Answer 1


There are several things you could do to reduce the visible effects of lagging. Just some ideas:

  1. Send the current acceleration, velocity and position values to the client, and let the client calculate the new velocities and positions until it receives a new data package.

  2. Avoid using frequently changing acceleration.

  3. You should consider defining states of the characters. For example: When a monster attacks, it has 2 acceleration, 0 starting velocity (vector pointing towards the player), and this state lasts for 2 seconds. You can send the identifier of the monster's current state, and the client will know the speed and acceleration values, and will know that it's gonna last exactly for 2 seconds. This way the client can draw the movement smoothly. If something happens in those 2 seconds, eg. the monster dies, then the client receives the new state ("Dying") and can show the animation of that state. Also, define default state changes. For example, a monster will have the "Dead" state as default after the "Dying" state. If "Dying" lasts for 3 seconds, and the client doesn't receive any updates for 3 seconds, your monster isn't gonna get stuck in the "Dying" state, but will die properly on the client side as well.

  4. You could implement some kind of lag compensation on the client side. For example, a small delay to the actions of the player, or effects of spells etc. If the player pushes the jump button, he won't jump immediately, but only after 40 milliseconds or so. The packet gets sent to the server with a timestamp, and forwarded to another player if necessary. The server and the other player's client will know that the actual jumping should be displayed only at Timestamp + 40 milliseconds. You can make this work with most actions without making the delay frustratingly high.

  5. Further reading:


Low traffic client synchronization with server in MMO

How do I keep an MMO synchronized?

  • 1
    \$\begingroup\$ This is a great comment and I totally agree. there is one more thing. If player interacts with monster on mid way, client should send the interaction data back to server and let server sync too. for the client side to sync with response of server you can use filling animations. like monster continues path then turns toward player and runs that way. this makes your monster look a little delayed but even in normal world it is natural. Imagine a drunk person, if you hit him it will take a while for him to realize what happened! \$\endgroup\$
    – AaA
    Commented Jun 28, 2012 at 8:44

You must log in to answer this question.

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