How can i code the grouped rotations for a rubics cube?
Asked Answered
V

4

0

Hello
I´m interested in how to program a working rubiks cube here in godot.
I know i can create a bunch of meshinstances with cubemeshes inserted and stack them into a big 3x3x3 cube.
But how can i make some of theese pieces rotate as a group around the group-center
and than sone of theese pieces rotate around another axis together with other pieces as another group?

i want to rotate a face of the cube by clicking it´s center-piece.

Varmint answered 14/8, 2022 at 19:50 Comment(0)
C
0

Right off, I would dynamically add the cubes to a parent node (Spatial) that is positioned at the rotation point you want to spin the pieces around (like the top center), perform the rotation by rotating the parent (which will rotate all the children), and then un-parent the nodes so they no longer are manipulated by the parent node’s rotation anymore. I’m not sure how feasible this is though, but that is what I would try if I was trying to make a rubics cube.

Conscription answered 14/8, 2022 at 20:24 Comment(0)
V
0

i´m not sure, if they stay at the rotated positions while un-parent them.

And how can i make the systen detect a click on the middle square of a cube-face to trigger rotation

Varmint answered 14/8, 2022 at 21:55 Comment(0)
C
0

Varmint it should stay in the same position forums once it is un-parented, I think.

For detecting the click, you will probably want to raycast from the screen: https://docs.godotengine.org/en/stable/tutorials/physics/ray-casting.html?highlight=Ray-casting#d-ray-casting-from-screen

Conscription answered 15/8, 2022 at 16:32 Comment(0)
V
0

Now twisting one face works, but if i twist another face on another axis than, one corner-piece of the edge, that belongs to both twists is not re-parented for twisting this time.
Which one it is, depends on the direction of the first twist.

It seems, that the reason for this are not hidden inaccuracies in the translation values, because it also happens, if i cast the translation value to an int for comparing.

I tested this with this print-command:
print(cubie.name, ": ", offset, " = ", cubie.translation.x, " -> ", cubie.translation.x == offset)
Output for the not re-parented piece:
Cubie1: 1 = 1 -> False
Which one it actually is, depends on the rotations on the first chosen axis.

Here is the repository of my project:
Rubiks_Cube githup

Varmint answered 19/8, 2022 at 17:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.