UDK and Rubik’s Cubes

I haven’t solved a Rubik’s Cube in years, but for some reason a few days ago I woke up with an idea for something involving the fiendish little puzzle. Imagine, if you will, a Portal-esque lab environment (white cubes, weird moving machines, etc.). Then imagine that this  place is actually the inside of a Rubik’s Cube.

Yes, I did just say inside.

My main “point” — if you could call it that — was that as the cube rotated so would you. If you happened to be in a rotating cubie, oriented vertical, and suddenly got turned on your side, “gravity” would now be pulling you sideways. And as you moved into cubies that hadn’t gotten rotated, you would enter them at an entirely different angle.

Of course, the mechanics of a Rubik’s Cube are insane to think about. Before reading on, ponder this for a moment: how would you make one in UDK? It seems simple until you realize that at any moment any one of the 27 cubies making up the larger cube could be in any place, in any orientation. That’s a lot of variability, and nothing that simple constraints can keep track of.

But after untold hours, I managed it:

Because I plan to use this for something, I won’t be releasing code yet. I can tell you, however, that there are a total of 81 InterpActors that make up the cube, along with 26 special actors I made especially for this purpose. Most of the functionality is also handled by triggers and Kismet.

I will also tell you that float imprecision is a massive pain, and I hate how UnrealScript doesn’t have a “fuzzy float == operator” like many other languages so that 259.997 really does equal 260.000.

Advertisements

5 thoughts on “UDK and Rubik’s Cubes

  1. Actually UnrealScript does have a “fuzzy float equal operator”, it’s called Approximate Equality and the operator is ~= . The precision for the compare however is 0.0001 if I’m not mistaken.

    • Yeah but apparently the 0.0001 is set…some languages like C++ let you specify the epsilon so for example you can say if A – B < 0.7, then A = B. Something like that would have come in handy here since whether or not the cubes rotate depends on their (float) world coordinates being equal.

      • Oh I see. Well for anything other than that I previously needed, I just wrote a compare function in object class which you could use with different epsilons. Of course it wouldn’t be like a native function but works quite good.

        Never tried, but you might even be able to override the operator~= function, if all your epsilons are the same. This way you’re not worried of extra function calls.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s