Collision detection - server side

Hello, I am making a multiplayer game with LibGDX, but the libgdx only installed in the client. which means the server is a complete pure java project.
I use Tiled maps for the game, with libgdx its really easy to do collision detection with all the tiled classes, but with pure java project its nightmare (the server).

So how can i do server-side collision detection? or to simplify the question, how can i read tiled maps without any libraries but with pure java?

I have some ideas in mind, i will test them and share them is they are helpful, but please post yours either. thanks :slight_smile:

Dont use collission detection server side, install libgdx or implement your own system.

How are you going to handle races to occupy locations?

What do you mean? you think i should make client-side collision detection? if that’s what you meant, you are right, but i will make the client side collision detection for prediction / interpolation, but the actual collision detection will be server side, other wise hackers will hack the collision detection without problem, and will cheat the game and ruin the multiplayer experience.

I don’t understand can you explain more? thanks

It seems like very good idea: do physics on the server and later sync up.

the problem is: latency. many elements complex physics, now youre getting a lot of latency =/

if 1000 players send a physics request to the server, it has to calculate them all. instead of everyone for themselves. and if the code is consistent the physics SHOULD behave the same for everyone.
of course the server could also have a thing where it just calculates the physics in an area and distributes the positions again and stuff

pretty sure there are whole books on this topic

What do you do when two or more entities try to move to the same location at the same time, or nearly the same time. Your collision detection logic is not instantaneous, so both calculations will start (not knowing about the rival move) and calculate that the new location is clear… the end result is two entities now intersect. (I’m assuming your server is multithreaded here.)

Basically, in my game the players can collide each other, in my game it looks completely fine, just every player will see his player on top. additionally it even looks illogical if the players can’t move through other players. i tested it by the way.

Hello,
So as nobody could really help me, and i couldn’t find any documentation or libraries to use tiled maps, i don’t mean libraries like libgdx, i mean libraries for easy checking, customizing the maps and tiles, collision detection, and everything you want. but a library without any textures to load or using OpenGL and your graphics card in order to work. just a library to work with the map without rendering it (like server sided collision detection).

So extremely long story short, i created a basic library, which i can give to you all if you want.
It works like this, exactly how i want it -


TMXMapLoader.Load(); // Loading the TMXMapLoader
TiledMap map = TMXMapLoader.readMap("assets/maps/foo.tmx"); // We reading the map

// Get Tiled Layer, which is basically the layers you create inside Tiled
map.getTiledLayer(i); // Get Tiled Layer with an index, returns TiledLayer.

// Get a tile/cell
map.getTile(i, x, y); // First parameter = layer index, Second parameter = X axis of the tile, Third parameter = Y axis of the tile. returns Tile.
map.getTiledLayer(i).getTile(x,y); // Same as above.

// Check if the tile has the `blocked` property, if yes we can't move through it or collide it (wood, stone), if not we can move through it (like air, water).
map.isBlocked(i, x, y);  // First parameter = layer index, Second parameter = X axis of the tile, Third parameter = Y axis of the tile. returns Boolean
map.getTile(i,x,y).isBlocked(); // Same as above
map.getTiledLayer(i).getTile(x,y).isBlocked();  // Same as above

// Get whatever you want
map.containsKey(i,x,y, key); // Get any property of the tile
map.getTile(i,x,y).containsKey(key); // Same as above
map.getTiledLayer(i).getTile(x,y).containsKey(key); // Same as above

// Get Tileset
map.getTileset(i); // Just get a Tileset with an index

// Get properties of the Tileset
map.containsKey(i, key) // Get any property of the tileset
map.getTileset(i).containsKey(key) // Same as above


That’s what i remembered, you can do basically everything, very easy to use. i added bunch of useful functions and more advanced than those, but no time to show.
tell me what you think. its not pro or something just created something fast that is exactly what i needed, and couldn’t find something like this nowhere.

If you want i can give it to you all.

Actually I am doing something very similar in my game. The whole world runs without any rendering or OpenGL, as a pure Java headless application. I also built collision detection from scratch.

So basically you want libtiled-java.

Yeah… i couldn’t understand how to get cells in the map.
As you can see in what i did, you have this function

map.getTile(i,x,y)

I couldn’t find something like this in libtiled so i decided to create a library myself.

I believe for that it would be something like:


((TileLayer)Map.getLayer(int i)).getTileAt(int tx, int ty);

It looks like the methods you’ve written are pretty close to the original. I will say I’m surprised by the lack of documentation for the library (libtiled-java, not yours), but the source is straightforward and compact enough that a quick “find” command is usually enough to get pointed in the right direction.

Either way, it may be something to keep in mind in case you hit a hiccup with implementing a feature in your library, and need to see how it was done before.

Cheers. ;D

Hey thanks, i tried this command in lots of ways, and i did exactly what you wrote here… but it still didn’t work and returned null… does it work for you? if it does i will try again

Anyways, I really like my library, it has a lot more features then libtiled and imo its more flexible, effective and useful, so i don’t really see why should i switch to libtiled.

Since the internal data structure of a TileLayer uses a 2D array of non primitive types, null is a valid return value for the function when no tile data has been set for a particular map offset. The format that I posted in my earlier reply does indeed work when using libtiled.

By all means, stick with what works for you. :slight_smile: My original reply was a response to your assertion that you couldn’t find a stand alone library to work with Tiled maps on the server side. Even if it’s not the route you chose, it may come in handy if somebody searches for similar info in the future. :wink: