Always rotate a quarter past original

This little problem has me bummed out for quite a while now and searching for a similair problem hasn’t brought up any answers. I’m creating an editor tool where users can create stuff much like K’nex.

Now the problem is that I can’t really make it so that when a stick piece is clicked in a circle piece it will rotate a quarter further relative to the circle piece. Manipulating rotations directly with stuff like ‘+90’ or using Rotate(Vector3.left * 90) don’t give the desired outcomes.

See it like this: You start with a vertical object. The second object that is attached to the first one is horizontal. The third object attached to the second one is vertical again etc.

There has to be something better than this. Maybe something like Quaternion.Inverse but only for a quarter?

I hope you guys can help me with this.

You should setup one of the circle pieces as a gameobject which has it’s origin in the center of the piece. Now you should attach 8 empty child objects to that gameobject. place each empty gameobject right at the bottom of each notch. You should orient those childs, so the forward-axis (blue) points outwards. The up-axis should be perpendicular to the round plate.

If you want to attach two round pieces you have to pick an attachment point on each piece.

A method like this, which takes the two attachment points as reference, would add the second round piece to the first piece and rotates the piece accordingly:

void Attach(Transform aP1, Transform 1P2)
    // the actual pieces
    var p1 = aP1.parent;
    var p2 = aP2.parent;
    // temporarily make the second piece a child of it's attachment point
    aP2.parent = null;
    p2.parent = aP2;
    // move our second piece to the correct position and align the rotations
    aP2.position = aP1.position;
    aP2.rotation = aP1.rotation;
    // rotate the second attachment point by 180° around the up axis
    // rotate it again by 90° around the forward axis
    // the pieces are now in their final position.
    // Make the second piece a child of the first and re-attach the attachment point object to the second piece
    p2.parent = p1;
    aP2.parent = p2;
    // finally we disable both attachment points so we know they are already "occupied"

This basically can also be used to attach a stick to a round piece. All you need to do is add some attachment points to your stick with different orientations.

*ps: I’ve written this method from scratch and haven’t tested it yet.