Sign in to follow this  

server side game object location tracking

Recommended Posts

snacktime    452

I'm working on an open source server side game engine and am tackling how to track game objects in 3d space.  


The basic idea I am working with is that the server will track moving objects and record their location.   I was thinking about dividing up the space into cubes of equal size, and doing enough math to figure out what cube an object is in whenever I record their current location.  With something like this 'objects near me' becomes an efficient query, as I just get the objects in your cube plus adjacent cubes.


But having spent most of my career working with server side code, 3d math isn't something I've ever really had to deal with, so I'm starting from scratch as to what the best algorithm would be, and what libraries would help me the most.  I'm using jruby,  so libraries in java or C would work, although I'd prefer java.


I was also toying with the idea of using a 2d grid and a 3d space made of cubes.  If I know the location of an object on the 2d grid, I'm thinking I can do some quick math to get objects that are within X number of 3d cubes away by just looking at the z axis of the objects.  So if I have a player in a known cube, and I want to get all other players in that cube and all ajdacent cubes, I could just compare the z axis of all the objects I got from the 2d grid calculation.   It wouldn't be an exact calculation, In order to get all players within range,  I'd end up with some players outside of the range I really want if I use a number large enough to get all players within range.


But maybe I'm overthinking this, and the math  isn't really that expensive to 'do it right'?



Share this post

Link to post
Share on other sites
Waterlimon    4398
Yup, you want a spatial partitioning system to speed up spatial queries. Theyre more like "find potential collisions/nearbies" (is that a word?), you still want to do the actual check, at least on the edge cases.

A grid will work fine. A hashmap with 2D/3D coords as keys will work too if a grid takes too much space, since a hashmap is sparse.

Hierarchical solutions work too (quad/octree, whatever else there are) especially if you have a wide range of object sizes.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this