Hi Everyone !

I'm a Godot newbie and I've started a new online 2D grid-based game project using Godot for the game client. Following a very cool tutorial, I'm using the TileMap node to build my game map.

My question is : is it possible to export the TileMap collisions data as a 2D matrix into a binary file that I can then load on server-side to perform world collisions and pathfinding ?

Thanks !

Welcome to the forums @Solimy!

I do not think there is any way to export the collision data from a TileMap, at least not using a built-in solution. You might be able to get generate a matrix binary file by iterating over each tile though, but I have not tried it myself so I'm not positive how doable it is. If you have a tileset that is just collisions though, you could use the get_used_cells function to return an array of tiles containing collision data. Then, especially if all the collision shapes are the same, you could probably convert that into an array of positions and send it to the server for server side processing.

6 days later

Hi TwisterTwigleg,

Thank you for your answer !

I tried the solution you suggested, however it gives me all the used tiles, even the ones with no collisions.

To solve this issue, maybe I could draw my map on two distinct tile maps, one for the "walkable" (like grass and dirt) tiles and another with the "not walkable"(like water or void); but is this a good idea ?

Do you think it could be also a viable solution to parse the tile map directly from the .tscn using the Godot headers files ?

Thanks, Solimy

@Solimy said: Hi TwisterTwigleg,

Thank you for your answer !

I tried the solution you suggested, however it gives me all the used tiles, even the ones with no collisions.

To solve this issue, maybe I could draw my map on two distinct tile maps, one for the "walkable" (like grass and dirt) tiles and another with the "not walkable"(like water or void); but is this a good idea ?

Yeah, that is what I would suggest doing, as then it should be easier to quickly tell which are which. It does increase the effort needed to make maps though, so there is that downside.

Do you think it could be also a viable solution to parse the tile map directly from the .tscn using the Godot headers files ?

Good question! I don't know, I haven't looked at how the tile map data is stored in the .tscn file. Depending on how it's stored though, this could be a viable solution but right off I am unsure.

TileMap collisions are depcreated use something else, here we go AI, nowadays , video games suffers from AI ...

@epicspaces said: TileMap collisions are depcreated use something else, here we go AI, nowadays , video games suffers from AI ...

TileMap collisions are not deprecated, they are still commonly used today and are supported. To the best of my knowledge, there isn't currently any viable AI-based collision system for game engines currently, and certainly nothing that would run on the majority of consumer hardware.

5 days later

Hi,

Thanks for all the responses !

In the end it was very easy to parse the .tscn to get the collisions informations. It's all plain text and reading this code was pretty helpful too. https://github.com/godotengine/godot/blob/59d98ed3bb1ed744600e599f997c817f63157d83/scene/2d/tile_map.cpp#L836 https://github.com/godotengine/godot/blob/59d98ed3bb1ed744600e599f997c817f63157d83/scene/2d/tile_map.cpp#L869

I will be using gogot ai to gain time on server-side and calculate players path (hackNslash style gameplay) on the client-side, but I will have to check those paths on the server-side to prevent cheating. And I want my server to stay stateless and scalable using redis as global storage and lazy collisions computation (totally experimental though).

Thank you !!

EDIT: link to the code