- Home /
Dealing with rotating objects on a dynamic axis
Not sure exactly how to phrase this question.
I'm working on making a Rubik's cube, just so I'd have something simple to become familiar with Unity.
I have a GameObject that contains all 27 smaller cubes. The game object can be rotated freely, so when a set of 9 cubes needs to be rotated, I have two problems.
1) How do I determine the axis on which to rotate the objects?
I have a Vector3 of Euler Angles that represents the rotation of the cube as a whole. Just calling transform.rotate(VectorOfEA), whether I define a space or not, doesn't seem to do the trick.
2) How do I determine which 9 cubes should be rotated?
I have the position of the cube currently being moused over, the same Vector3 of Euler Angles as above, and the direction the user wants to rotate it. If the cube as a whole never rotated, it'd be easy because every smaller cube would share an x, y, or z coordinate with 9 others.
I feel like a little trig would get me right through this, but I can't imagine what it is. Please tell me if I'm not explaining my question well enough.
Edit: Forget it. Didn't realize that the smaller cubes didn't just rotate, they also move.