0

I'm trying to rotate the planes of a Rubik's cube using RotateAround, my problem is in determining the axis vector that a certain plane needs to rotate around, I'll always need to use the vector that passes through the center gameobject but using Vector3.up/ down/ right/left is useless especially if the cube rotates and changes position, any suggestions? :\

for instance, this is the line I use to rotate the green plane, green is the center gameobject in this case

    Parent.transform.RotateAround(green.transform.position,WHAT AXIS VECTOR?,100*Time.deltaTime);
msLangdon95
  • 77
  • 1
  • 13
  • 1
    hi msLangdon, just FYI, I can warn you, this is *extremely* difficult to do well. it is not a job for a beginner or learner programmer. one basic tip, note that Transform.Rotate can work **in local axis** (read the doco). that may help you. it's alway "local up" if you see what I mean. – Fattie Apr 18 '16 at 11:32
  • well I'm not a beginner in programming and math in general, I'm kinda new to unity :\ is it that hard? :\ – msLangdon95 Apr 18 '16 at 11:33
  • 1
    ok, in the first instance master the difference between local and world axes, enjoy – Fattie Apr 18 '16 at 12:00
  • Possible duplicate of [Rotating faces Rubik's Cube C#](http://stackoverflow.com/questions/15572326/rotating-faces-rubiks-cube-c-sharp) – Fattie Apr 18 '16 at 15:07

1 Answers1

1

What I would do is the following:

On positions of each of 6 central pieces on every side I would place an empty game object. I would rotate them manually so that they all have their local Y axis pointing outward from the surface (switch to local space in Unity for this).

Now, whenever I would need a rotation of a side I would:

  • parent all 9 pieces of the side under my empty game object for THAT side
  • rotate the parent game object 90 or -90 degrees around local Y axis
  • un-parent all 9 pieces (so that they are ready for next cycle)

All you'd need is to check these out from Unity Docs: transform.parent, transform.localEulerAngles and some rotation functions, probably Mathf.Lerp and Vector3.Lerp for smooth rotations.

Nika Kasradze
  • 2,834
  • 3
  • 25
  • 48
  • 1
    this is quite correct. *unfortunately*, totally setting aside "just" the hassles of moving stuff around like that in Unity; the whole thing's almost impossible unless you follow an mvc pattern and you have a data structure that understands all the pieces moving around. it's a real pain! – Fattie Apr 18 '16 at 15:06
  • it is a real pain indeed :| but thanks I'm still trying – msLangdon95 Apr 18 '16 at 19:35