0
votes

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);
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
well I'm not a beginner in programming and math in general, I'm kinda new to unity :\ is it that hard? :\msLangdon95
ok, in the first instance master the difference between local and world axes, enjoyFattie
Possible duplicate of Rotating faces Rubik's Cube C#Fattie

1 Answers

1
votes

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.