A simple puzzle - just a bit of fun

I’ve always been interested in puzzles of all types, ever since I was a kid. The other day, I bumped into a puzzle and thought maybe I could build it with BJS. Here is the result :

The Square Puzzle

It involves arranging the five coloured pieces on top of the white central square, and as you can see from the data at top left very simple. You can only see 6 meshes - one other mesh is invisible (the camera target) and one is an “empty” that is the parent of the coloured meshes (makes them easier to find in the code). With my poor coding skills, it took me way longer to write the code than create the mesh parts in Blender 2.90 !

What I have not figured out is how to determine success. The initial .babylon file loads at the solution, then the code scatters the pieces around. You can select a mesh with the mouse, then use the WASD keys to move the part chosen Left, Right, Up and Down, the R key will rotate a piece. So just move them all into the white square. But how do I detect they are all back to their original positions?

I tried saving all the meshes “solved position” before I scattered them around, by assigning the piece position to an array called “theStart” figuring that I could check on how close the final positions are to original starting positions - but when I look at what is saved I find this when I post the result to the console:

Object { _isDirty: false, _x: -4, _y: 0, _z: 3 }

which has this “isDirty” parameter as well as the position data.

So anybody have ideas about success could be calculated??

On a more positive note, given the simplicity and small size of the .babylon file, it should be possible to add a number of puzzles all in one file - make a neat little time waster !! :slight_smile:

And one thought I had while playing with the code - it would probably be easy for @Dad72 to go to his workshop and make these kind of puzzles with coloured woods and a bandsaw :slight_smile:

Stay Safe All, gryff :slight_smile:


I should perhaps add that as the shapes will all fit nicely in the white square, there are actually 4 solutions to this 3d effort, as the parts fitting in the square can all be rotated by 90, 180 and 270 degrees,

To get around that, I could taper the square slightly before using the blender knife tool to cut the pieces.

Stay Safe All, gryff :slight_smile: