I have read all of the answers here about tracking player locations, but still have some questions. I don't seem to understand how to do this efficiently, and feel that the internet could greatly benefit from an effective solution that is easy to find.

Anyway, I am making a 2d mmo (the first multiplayer game I have made that will handle this many people) and can't seem to come up with a good way to manage the location of players, and alert other players when they are near them. My map is tile-based, and I want the clients connected to know when a player of another client is withen 200 blocks from the other client.

My map uses x and y coordinates, and each block is a value. I read something I was linked to by a similar question here, that explained that a good way of managing this sort of thing is to create a box around each player, and to alert both player's when their boxes overlap (assuming I understood it correctly).

But how should I create these boxes without wasting tons of computing power and resources? I thought of storing it in SQL database, but that would be too slow. I then realized that player locations would have to be stored in the RAM. So what are some previously used strategies to track player movement in the RAM? Should I store a variable for each player containing the coordinates withen 200 blocks from them, and constantly have the server checking to see if two players overlap? This doesn't seem very efficient, and I believe that I am going about this the wrong way.

Any help is greatly valued.

  • 1
    \$\begingroup\$ What you could do is subdivide the world into logical regions, and use the player's current region and surrounding regions as a query filter when searching for nearby players. When a player enters a region, that region ID is stored in the database for the player. When finding players, you get all region IDs connected to the player's current one, and use those as a filter to select players by region, which will cut down on the number of player entries selected. \$\endgroup\$ Commented Jun 14, 2013 at 18:14

1 Answer 1


If you're willing to ease on the requirement that a client should be informed of other clients that are exactly 200 blocks away or closer, then here's an idea: split your map to squares of, say, 200 blocks each side. Then you can keep track of where the client is, and inform the client of all other clients in the adjacent squares. More detailed discussion can be found in another question.

So, instead of having a square of 200 blocks around each player, you'll have statically located squares, each of which know the clients contained within them.

Also, see information about quadtrees. Quadtrees are often used in collision checking, and in your case you want to know a kind of collision.


You must log in to answer this question.

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