heygleeson / godot-ldtk-importer

LDTK Importer for Godot 4
MIT License
134 stars 12 forks source link

How to import collisions? #5

Open ValeriyDP opened 10 months ago

ValeriyDP commented 10 months ago

Hi I'm pretty new in the Godot and LDtk i could not get how to import a collision? I successfully imported ldtk file, it has 2 layers but do not have any mentions of collisions itself.

Thank you in advance.

heygleeson commented 9 months ago

Sorry for the late response.

Collisions can be added in the generated TileSet (found under "/tilesets/" in the folder of the LDTK file). These are preserved even when you make changes to the LDTK file/tileset (in most cases).

With the Tileset selected (and viewed in the Inspector):

Godot_v4 2-stable_mono_win64_23-12-18_14-23

If you want to speed things up, and assuming most of your tiles will be fully solid square collisions, Click+Drag to select multiple tiles, then press 'F' to "Reset to default tile shape" (a full square).

gummycookie commented 8 months ago

heya, I'm planning a large project around this plugin and wondering what those edge cases are where the collisions aren't persisted across reloads?

The plugin has seemed to handle everything I need so far so awesome work on this, its a huge time saver!

heygleeson commented 8 months ago

Things like modifying/deleting the physics layer or changing the tile size/padding on the tileset in LDTK would obviously break collisions. "Force Tileset Reimport" will also completely overwrite the existing tileset and remove any changes (so use it carefully).

But regular modifications like editing/resizing the tileset image should be totally fine (as long as LDTK can handle it). I can't identify all the edge cases where collisions wouldn't be persisted.

octoshrimpy commented 6 months ago

Is there any way to import a layer as collisions? I have some tiles that are used as background in one section, and as collisions in another. I have those split in LDTk as such:

image

and would like my player to exist between liquids layer and bg_decor_auto layer, while still colliding with collisions. right now i'm not seeing a way of handing individual layers other than maybe post-import?

previously i'd been getting around it by exporting to Tiled, and on import from Tiled, running this bit of code: image

avivajpeyi commented 1 day ago

Neat! In the docs you mention

While it is possible to add tileset collisions via a post-import script

How can one do this?

EDIT: found an example here https://github.com/afk-mario/amano-ldtk-importer/blob/main/addons/amano-ldtk-importer/examples/post-import-scripts/post-import-tileset-add-collisions-by-enum.gd