Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To give a bit of background, I'm developing an MMO in the web browser. Crazy? Yes, but it certainly isn't impossible. The server sends updates to the client by means of long-polling JSONp tags which are opened in advance and marked for updates to be sent at a certain timestamp.

The problem is that you simply can't pump too much information into a browser. At some point, there's a barrier as to both the speed and quantity of information that you can send, so I'm looking to implement some type of system that would allow the server to send periodic updates of remote users' positions rather than "realtime" updates. Is there any reliable way of doing this without shooting myself in the foot?

I've read about a heuristics technique that analyzes the motion of a player over time to generate a function which could be used to simulate the player's pathfinding "technique". This would then be used to interpolate the position of the remote player between updates. Any thoughts on this or another technique I could use?

share|improve this question
are you using the webSockets API? and is this going to be open sourced at all? – Rixius Aug 4 '10 at 15:43
@Rixius Most of the game will not be open source, though the various components I'm building it with are/will be. You can check out the realtime messaging server and application framework on github: – mattbasta Aug 6 '10 at 3:38
up vote 3 down vote accepted

Optimizing mmo network performance does indeed come down to movement prediction. Luckily there are a few different strategies you can use in your MMO with regards to movement, and some of them are much easier to predict than others.

If at all possible don't worry about where players ARE, worry about where they are going. Let's say your game has some sort of point and click interface where a player picks where they are going. This makes perfect sense for a mouse-driven MMO. In this case you do not have to update periodically with their current location. Instead, you just need to tell every client where each player is heading and when they expect to get there (and maybe some pathing info if you need it). You can then animate it entirely on the client. If a player changes their mind you can then send updated info to the clients. there may be a bit of rubber banding, but without direct player control it won't be noticeable. This approach can even be used in crazy physics environments, as much of Eve's motion is predicted on the client using complicated math.

If it's absolutely vital that your players must have direct movement control, you're then going to need fps-style movement prediction. This is probably overkill for any sort of web-based MMO (are your players really using controllers or wasd to move?), but you will need it if collision is important. In this case you end up doing a much more complicated version of the above, where the client will attempt to determine where a player is heading based on the position and velocity of a player that is sent down over the network. But the prediction errors here will feel much worse, especially in a laggy environment. Stay away from this method if at all possible.

share|improve this answer
Would you imagine that a FPS style is more difficult to program? From a programming perspective, the FPS-style movement is much easier to write. I do like the concept of mouse control, though. It would certainly simplify the task of hit testing (just don't let the player set an unreachable area as their destination haha!). – mattbasta Aug 6 '10 at 3:56
FPS-style network movement prediction is in fact very difficult to write correctly. Projects I have worked on have had one full time senior programmer devoted to just getting that right. – Ben Zeigler Aug 6 '10 at 17:51

Motion prediction is used by pretty much every online game these days, but it usually operates with an expected sync cycle of 100ms or less. Are you sure you can keep that kind of data rate without maxing out the browser? If you search for "motion prediction" you can find a lot of information, but assuming this is a 2D game the concept is simple enough (store a moving buffer of the last X positions, extrapolate next position). There is some complexity when you start dealing with how to move players that are out of sync from where the server thinks they should be (read: rubberbanding), but you can probably just ignore that for now.

share|improve this answer
Do you have any ideas on how this would behave with regard to hit testing? What if the prediction puts the user in an "unwalkable" area? Any idea what others have done? – mattbasta Aug 6 '10 at 3:40
At least for us, the client and server both run collision detection, but the server is authoritative. This means the client is trying to avoid moving people into objects (it will just stop them, as if they were running into the wall), and then the next time it gets an update from the server it will correct. – coderanger Aug 6 '10 at 4:38

I have no experience in this domain, but I've seen something that may be useful. If you know, or anyone else knows about this feel free to elaborate on it. A buddy of mine pointed me to this when I was talking about creating a multiplayer web-based game.

share|improve this answer
Thanks for the link; I'll definitely be exploring their code and seeing what they have to offer! – mattbasta Aug 6 '10 at 3:47

I'm looking to implement some type of system that would allow the server to send periodic updates of remote users' positions rather than "realtime" updates.

Pretty much all MMOs do this; it's not limited to those that want to run in the browser.

It's quite simple to get a basic scheme up and running:

  • The server has an interest list for every player, consisting of other players and NPCs.
  • If someone moves too far from the player, they're removed from the list, and if they move within range, they're added to it.
  • If a player moves, an update about that is sent just to the players who have this guy on their interest list. It doesn't have to be sent immediately - it can just be flagged up in the interest list as needing an update, so that it is sent in the next periodic update message
  • These updates can be skipped if one was already sent too recently. Your definition of 'too recently' can be based upon distance, or on a more complex scheme which evaluates how good a predicted position is likely to be (see below).
  • Clients linearly interpolate positions, predicting a character's path, and smoothly blend between the prediction and the reported position to correct errors, meaning updates don't have to be real-time to appear fairly accurate.
share|improve this answer

I think that the interpolation idea will not be useful to you. If your game is supposed to have realtime interaction between players, any delays in transmitting player actions would seriously damage the realtime aspect. If the game does not have realtime interaction, the periodic transmissions should be sufficient for any important events in the game.

share|improve this answer
I'm aware of this; I'm trying to make this as realtime as possible, though periodic transmissions are what I may be limited to (due to browser constraints). – mattbasta Aug 6 '10 at 3:43

JavaScript Sockets!

There are several implementations but they all use either Flash or Java, which your page communicates with via a JavaScript library (since both Flash and Java can interact with JavaScript on the page). You can literally make C-like socket calls to establish a connection, send/receive data, and close a connection (and whatever else you do with sockets).

Here are a couple:

I highly recommend taking this approach. However, it would also require a different server technology; which is a good thing, but it is a change and depending on how advanced your server is, that could mean a lot of lost time...

Oh, and there's also WebSockets coming soon. So if you use one of the above libraries and adapt your server to use socket communication, then you can just swap in WebSockets as it becomes more accepted!

share|improve this answer
I'm actually using my own implementation for the communication medium (see; it's based on WebSockets, XHR streaming, and JSONp longpolling), so that's covered. I'm trying to find out what the optimum means of interpolating user position between data transmission would be. – mattbasta Aug 6 '10 at 3:52
Oh, I'm sorry, I must have misinterpreted your question. – Ricket Aug 6 '10 at 13:43

Your Answer


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.