# Can ANYONE HELP with this? (Object Rotation)

Hi,

I am trying to tell Unity to find an object at a certain input coordinate and rotate it 45 degrees.

Its a 3x3 Rubiks Cube and I want to be able to rotate the different sides on command. I have grouped the faces of the cube into parent objects and now need to find a way to find them in space and rotate.

So far I cant figure out how to do this???

If anyone could shed some light on this for me I would much appreciate.

Ben

What do you mean by “find them in space”?

If you’re modeling this ahead of time, or building on the fly, you can pre-store references to each item. Are you doing that now?

Having some extra information on how you have things structured in your scene and what code you may have already tried will help guide us a bit more. Let us know!

By “find them in space” I mean find an object that is at a certain co-ordinate?

All I am trying to do is make a working model of a rubik’s cube so that the user can push a button to control the rotation of the different sides. Is this possible??

So far I have made a 3x3 cube made up of individual cube objects. I assumed the best way to make this into a working cube would be to group all the rotatable sides of the cube into parent objects. Then program into the script that if say button ‘X’ is pushed the script will locate the parent object at coardinates ‘X,Y,Z’ and rotate it 45 degrees. I no longer think this will work because as the cube gets rotated the parent objects will be broken up. Im lost.

“Ooooh, I love logic puzzles. Now let’s see…”

I almost think solving the cube would be simpler than building it. :roll: Nevertheless, I think what you want to do is to parent the side to the center block, then rotate that. When they move, reparent the proper blocks to the proper pivot and animate. Basically “grabbing” a side to move it.

The next step is to find which blocks to grab. I suggest storing the block identifiers in a 3 dimensional array. Turning it would be a challenge, though. Off the top of my head, I’m not sure how it would be done, but I think it would be simple enough once it’s done.

Another approach is to track the location of all of the cubes and do the parenting manually by finding positions. You would have to be careful to avoid rounding errors causing problems, but it should work. Use `var blocks : Transform[];`to expose an array in the inspector, set it to however many blocks you need to track, and drag and drop them into the slots. Should be easy from there.

Hope it helps.

I made this a while ago. I made it on a whim and thought it would take me maybe a day, but it took three days because it was way more complicated than I thought it would be. It seemed like it should be trivial but it’s really not, unless of course I completely overlooked the easy way to do it. Omega is right about the parenting and unparenting to group the individual blocks. As for detecting which side is clicked on, I ended up doing some shenanigans with raycasting and an invisible cube. In hindsight I think it would have been a lot easier if I didn’t allow free rotation of the entire cube but stuck to 90 degree angles instead, because trying to translate mouse dragging into the proper rotation took ages to get working consistently.

–Eric