2

I am making a rubiks cube generator with unity3D. My generator generates not only the cube, but also "Side objects" for each side of the cube as seen here:

Cube side example

These side objects are just Empty objects with colliders. These colliders could be used to turn the sides of the cube by setting everything inside them except other sides as their children when user clicks on the collider and then just rotating the empty, like this:

Collider[] collides;

void OnMouseDown()
{

    collides = Physics.OverlapBox(transform.position, transform.localScale / 2, transform.rotation);    

    foreach (Collider col in collides)
        {
            if (!col.CompareTag("Side"))
            {
                col.gameObject.transform.parent = this.transform;

                Debug.Log(col.gameObject.transform.name);
            }
        }
}

Here is where my problem comes: I can not figure out the logic to what side to parent.

Let's imagine an event like this:

enter image description here

The user clicks on the area marked with red. Which side reacts? I have tried doing something like calculating the path users cursor has went since first clicked to the current position and comparing it to the orientation of the collider, but I haven't got it working.

Also when I make the cube pieces a child of the collider they become small.

How should I implement this?

4RZG4
  • 50
  • 1
  • 10
  • You could try making the colliders thinner, You only want colliders on the surfaces. If you make them thinner there will be less overlap and they will only cover the important part of the cube. – Tom Coldenhoff Sep 27 '20 at 13:12
  • @TomColdenhoff The colliders already cover only the important part of the cube, and the colliders will overlap no matter what, because there is one collider per on row of pieces – 4RZG4 Sep 27 '20 at 13:25

0 Answers0