The proper way to use tilemap 2D for non-trivial sprite shapes and collision phyics effects?

Hi, I’ve tried searching all over and I can’t seem to find proper answers on what I would think would be common problems. For context, my game involves a ball bouncing around levels created with tilemaps. I have two questions.

  1. First is dealing with colliders for tiles that are non-trivial in shape. For example, I have tiles with circular shapes like this:

As you can see the collider isn’t accurate around the curve. The problem is I need to generate precise colliders for my game, which Unity’s tilemap editor doesn’t seem able to do. I know about going into the sprite editor of the tileset and editing the custom physics shape manually for each tile, but it’s really not feasible for shapes like circles. I’m thinking just forego colliders in my tilemap completely and instead generate PolygonColider2D’s for my entire tilemap via code which seems like a significant amount of work… What is a proper way to deal with this problem?

  1. I want different surfaces to apply different physics effects. For instance, some surfaces will be more bouncy or apply a force or slow down the ball, etc. The solution I have in mind is to have a collider layer in my tilemap and also a layer that overlays on top indicating the surface type.

Example: the purple surface is an overlaid tile on a different tilemap layer than the layer with collision. So if the ball hits that part, it’ll be bounce farther than the white surfaces (or whatever physics effect I want).

Then in the code monitor every single collision and compute the tile and surface that’s being collided with and apply the corresponding physics effect. Does this seem like the appropriate solution? Just want to make sure I’m not missing something more obvious. I know you can do stuff like add GameObjects to tiles with the 2D Tilemap Extras package, but I don’t really see how that’ll help when I want colliders to be contiguous across all the tiles. I notice the physics for the ball get wonky if it collides at points where two colliders meet so I want to avoid having that.

Thanks!

Your suspicions are correct.

You can use a Composite Collider 2D to merge the colliders of its children automatically. Don’t merge those colliders that need distinct properties like bounciness because there’s only 1 material per composite. To specify which children to merge, only mark certain children with Used by Composite checkbox.

For your case, at least certain special surfaces should be gameobjects so that you can provide a different material. There’s only 1 material per tilemap collider or composite, so you need different collider2Ds for special cases.