Additive Rotation Quaternion Animation

I’m trying to animate the rotation of portions of a rubik’s cube (9 given cubes rotate around one of three cardinal axes by 90 degrees), and am using mesh.rotationQuaternion and Quaternion.RotationAxis to achieve this.

The position of the cubes almost perfectly follows the correct path, and the rotation goes off without a hitch as well. However, a cube that has already moved erratically snaps when it need to be moved again. I suspect this is because the first keyframe sets the quaternion to what it expected from a non-rotated cube. A smaller issue is that the cubes seem to shift closer to the center when rotated around 45 degrees.

It seems like using an additive AnimationGroup would be the best approach, but this just fails miserably every time i try.

Is there any way I can avoid these issues? Is this the right approach?

The problem is that the positions are interpolated linearly, whereas they should follow a circle.

You could try setting the pivot point of each cube to the position of the central cube of the rotating face and add only the rotations to the animation:

In this PG, I’ve hard-coded the rotating face so that I know which is the central cube. In the general case, you’ll need to find out which is the central cube, depending on which face is rotating.

2 Likes

After a repeated rotation, the cubes reset to their original positions (shown as the colors resetting) - the desired behavior would be to have cubes simply shift again (like a 180 degree rotation)
Changing cubes’ pivot points seems extremely futile as they all fly out into space (why.)

Applying your code to a fuller example yields these results:

To simplify things, I updated the code to remove the rotation from the transformation matrix at the end of the animation.

However, to retain the right orientation of the cube, I bake the current rotation into the vertices.

I also rename the cube (as you did), but after the transformations explained above are applied, so that after the animation we end up with the exact same configuration of the Rubik than before the animation: same cube with same names at the same position, and not rotation (quaternion).

PG:

2 Likes