#Collision for jigsaw pieces (Concave/Convex)

1 messages · Page 1 of 1 (latest)

broken elm
#

I have created jigsaw pieces by creating a mesh of points. I now want to add a collider that reflects the shape of the jigsaw piece. I'm new with this discord thread but I added a picture of how my shape usually looks like. However, for debugging purposes I have chosen a simper shape and that is in the other images. The solution should work for both.

If I create a bunch of duplicates for the points, to make segments. I can make a concave collider that looks my piece (the simplified cubey piece). However, a hollow collider won't work. I want my mouse to collide with the piece to be able to pick it up and drag it. Concave colliders are always hollow? So I cannot use a concave collider? But the shape is concave?

If I try with a convex collider instead, it looks correct. (The blue is from when I have collision shapes Visible Collision Shapes on). But the collision doesnt work, I used signal mouse entered and mouse exit. When trying with a square piece (flat sides on all sides, impossible on a real puzzle :P) the mouse entered signal works so it isnt that. I get the warning: "Concave polygon is assigned to ConvexPolygonShape2D. So convex collider is probably not the way either.

How should I tackle this problem? I guess that it is possible to divide the jigsaw piece into multiple colliders but that feels quite hard for my more traditional looking jigsaw pieces. I would like to create some variations aswell in the future. I would have hoped that I could just input my points that define the shape and get a collider someway. Is this possible?

I talked with a friend and he told me that instead of colliders I could use a shader of some sort. He said that I could do something along the way with assingning the puzzle piece id to each pixel in a piece. And then when the mouse pointer is above a pixel you can check for the id. Idk, that solution feels a bit strange.

Would be happy to get some help/ideas :)

#

So the first picture is how my pieces look like in the more complex way, the outlined picture is when using a concave collider on a simplified piece. And the last picture is when I use the convex collider on the simplified piece.

sage atlas
#

Is there any specific reason you need physics for this?

broken elm
#

I want to be able to move the pieces

#

But the pieces does not need to collide with each others

#

Just against the mouse

sage atlas
#

Aah, then you should use an Area2D. I don't know if you mentioned what you're using.

When you create a CollisionPolygon, you can choose the mode between SOLID and SEGMENT. You want to use SOLID.

broken elm
#

Yeah I have an area2d with either a convex or concave shape as a child (a shape2d). I will look into CollisionPolygon

broken elm
#

Hey I don't know how I missed CollisionPolygon, but it seems to work just how I want it! I just had to remove some duplicated polygons in because I draw each side individually so the corners were duplicated. This is how it looked for the simplified piece

#

And this is the more traditional

#

Thanks 🥳 @sage atlas!

#

How do I mark it as solved?

sage atlas
#

Just add the solved tag, glad it worked :)