godot-ldtk-importer icon indicating copy to clipboard operation
godot-ldtk-importer copied to clipboard

How to import collisions?

Open ValeriyDP opened this issue 2 years ago • 5 comments

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.

ValeriyDP avatar Nov 24 '23 17:11 ValeriyDP

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):

  • Add a new Physics Layer to the TileSet
  • In the Tileset Dock (on the bottom), toggle 'Select' mode to modify tile properties.
  • Select a Tile, then navigate to Physics > Physics Layer 0 and modify the collision shape.

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).

heygleeson avatar Dec 18 '23 03:12 heygleeson

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!

gummycookie avatar Jan 11 '24 01:01 gummycookie

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.

heygleeson avatar Jan 16 '24 06:01 heygleeson

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

octoshrimpy avatar Mar 11 '24 03:03 octoshrimpy

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

avivajpeyi avatar Oct 02 '24 20:10 avivajpeyi