Merge collision shapes to one big rectangle?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By juppi

Hey,

I’m using a tilemap with 16x16 tilesets. Some of these tiles have a collision defined.

Is it possible to automatically merge these collision shapes to one big collision shape together?

So lets say I have two 16x16 collision shapes next to each other, I then want to have one 32x16 collision rectangle. Is this possible?

Thanks!

This is how TIleMap works, it is always merged into one collision instance. It is impossible to normally detect collisions of individual tiles.

If You need this shape to be copied for some other instance You can use Geometry node. Its methods allow to build polygons based on vector2 arrays. This shouldn’t be to hard to feed all collider tiles positions to this method, create collision shape with polygon shape, and apply Geometry result as a new shape.

Inces | 2021-12-19 18:24

:bust_in_silhouette: Reply From: afk_mario

Ended up implementing it using the Geometry class to support multiple polygons and I think even holes are generated correctly.

enter image description here

This post goes into more detail on how it works.

Another post that helped me:

https://forum.godotengine.org/30006/build-a-collision-polygon-from-tilemap-outline

2 Likes