I’ve got two cubes. One cube shall rotate around the other. Essentially I have the following code:
How would I “translate” this into an animation? What happens if multiple cubes rotate at once? What are common pitfalls for this kind of thing?
This section should give you some ideas
Examples from this section
So I tried implementing this as best as I understood and this is the result: https://playground.babylonjs.com/#B6TPPB#10
I somehow failed in the logic / math part.
Ahh a Rubik’s cube, depending on the axis of rotation and the changed position of the a single cube then the cube’s pivot or parent will need to change. Tricky.
Search the forum for Rubik and check out the various suggestions as other have had a go at building a Rubik’s cube.
Yea I found some but I don’t seem to understand how the rotation works in Basic Rubiks cube. I made some changes to my playground: https://playground.babylonjs.com/#B6TPPB#11
I simplified the example by using a 2x2x2 cube. Somehow it seems as if the parts of the rubiks cube are rotated an additional time. I don’t know what is causing this behaviour
I could fix some issues:
cube.setParent(transformNode) instead of
cube.parent = transformNode to preserve transformations made on the cubes
- correct the rotation calculation to use the current rotation of the transform node
Still there’re errors if you rotate vertically and horizontally
You can also try looking at how I handled the rotating on this demo using parenting. I tried to look and see where you were getting stuck but TBH that part got pretty harry to get right. But OTOH since I wrote the code in that one it should be relatively easy to answer questions about it if you have any. GL!