How to fix coordinates after rotation?

Hello! I am create my first project in Babylon.js - Rubik’s Cube Game.

I have some trouble with rotations.
I have array with cubies and I filter their and select some cubies when a need rotate some cube’s face.
I change parent node for selected cubies, then I play animation for this parent and change parent again.

When I run animation again some cubies have wrong coordinates (previous value equal -1, but new value equal -2.220446049250313e-16) and I have a bug :frowning:
I think I need reset some parameters for cubies after transformation, but I don’t understand which parameters.
Could you help me with this problem please :slight_smile:

rotate-bug

I created example in playground: Babylon.js Playground

Try setParent(null) after you are done rotating.

@adam, thanks for your answer!
I added this fix, but the coordinates still changed and bug remained :pensive:
https://www.babylonjs-playground.com/#1PV77K#1

If I logged cubie coordinates (cubie.position and cubie.absolutePosition) then I saw wrong Y or X coordinate, but in Scene Inspector coordinates is right. Maybe it’s a bug?

Forgive me, you may have already tried this, but can you not simply round the cubie positions after de-parenting?

            for (let cubie of cubies) {
                cubie.setParent(null);
                cubie.position.x = Math.round(cubie.position.x);
                cubie.position.y = Math.round(cubie.position.y);
                cubie.position.z = Math.round(cubie.position.z);
            }

Annoying the value doesn’t snap to a nice round number after the animation is performed (at least, for rotations that are multiples of 90 degrees).

Are the cubies sentient or? Is that beyond the scope of this model?

@kjg thanks, I didn’t think about the calculation error after rotation :pray:

Do you mean coordinates’ scope?