Sunday, April 19, 2009

Some Rubiks Cube Funstuff

Gonna post something fun for today, just because.

A while back I decided to see if I could tackle the challenge of rigging a Rubiks Cube, simply because I really love Rubiks Cubes, and I figured it would be an interesting scripting challenge. Although, admittedly, I have seen cubes rigged without any scripting, but anyway!

I wrote a script with some trial and error, and ended up with success! The video is old, and things were still in testing stages, but...

To sum it up: the script runs based on selections. When a controller is selected, it calls all of the cubes that have a Global/Local XYZ value that corresponds to that controller (basically the closest cubes), then groups them so that they can all be rotated . After the group is rotated and another selection is made, a script runs that makes sure the group is rotated in some increment of 90 degrees (if not, it corrects it), then ungroups everything, resets and freezes all transformations so that it can run again.

The code has since been updated, and there's now a Scriptjob so everything runs automatically, and I made a few other fixes to make things easier.

The real difficulty when it comes to this, however, is making it animateable, and also making it have a self-solver. Both are problems I have seen tackled in a few different ways (though personally I'd love to see the way Pixar did their rig for it from WallE), and thus far no two scripts I've seen have been the same - my friend Josh and I sat down to write our own scripts simultaneously, and we came up with two entirely different things.

Here, however, is one interesting approach to the whole method.

This solves the issue of animation, and it's also a very interesting way to set things up. I found this after I wrote my script. I have not tried to animate my cube, but I have figured out a way to write a solver for it (but then school sucks away all my time, so that hasn't been done yet).

I don't know, I just find different approaches to the same thing fascinating.


  1. This is pretty cool. Rubiks cube seems like a challenging exercise. I would love to tackle this problem, when I get time.

  2. It's a really good exercise in method and code efficiency, not to mention it's kinda fun. You should try it when you get the chance!