Jigsaw puzzle pieces generator

Hi All

I’m very new to Unity and game development (my first attempt actually) and would appreciate your help greatly.

I’m trying to create a jigsaw puzzle game for my kid and my general idea is as follows:

  • 2d
  • runs on mobile (probably just tablets)
  • I want to be able to generate puzzle pieces from a user uploaded image

I started out with figuring out how to generate the pieces and I’ve created the following mesh attached to a game object with a script -

I want to be able to create this geometry alone, and then reflect it/rotate it to create an entire puzzle piece which will be a single game object (assume I have the script for an “Outy” piece as well).

My questions are:

  • How can flip/reflect (not sure about the right term) this mesh and join the two flipped meshes together to create one face of the puzzle piece?

  • I’ve read about mesh combine but that requires a new game object and it seems wasteful in resources, even if it’s temporary.

  • How can I rotate a given mesh? this will allow to create different faces.

  • Am I in the right direction? truly a newb here, any advice applies.

Thanks

I wouldn’t generate complex jigsaw meshes.

Instead I’d just break the image into tiles. The tiles can be whatever width/height, but all the same width and height. So rectangles.

Furthermore, Make the actual tile ever so slightly larger than the actual gridded out area. So lets say you did a grid that is 4x4, each tile 1x1, make the actual tile 1.1x1.1. When laid out correctly, they would overlap.

That extra space is to allow for masking and showing the convex jigsaws.

Now, each tile we’d generate 4 sides… you could have ‘straight’ (for edges) and a convex/concave pair (the other for the neighbour). From these 4, generate a mask that would be applied to the tile. This mask would make transparent the parts of the overlap that shouldn’t be there, leaving just the jigsaw shape in line.

Now fitting together wouldn’t be collision matching. But rather sibling pairing. Tile (2,1) can only pair on its right with (2,2). So you stick them together… the masks make them look correct.

Thanks lordofduct

So i’ve been reading a bit about the concepts you talked about, and what i’m coming up with is using a transparent shader for the masking (is this right?). still not sure how i specify the actual mask shape (would be great if you have any reference for creating such kind of mask).