I successfully created a Rubik's Cube using Three.js, and everything is functioning as intended. However, I would like to add an animation when turning the cube instead of it snapping into place instantly. How can I achieve a smoother turning effect?
Below is the code snippet that I am currently using:
function turnOrangeSide(inverse) {
let x = 0;
let y = 1;
let z = 1;
orangeGroup = new THREE.Object3D();
scene.add(orangeGroup);
// The following lines group all parts of the Cube that need to be turned.
orangeGroup.attach(getIntersecting(rotationPointO, x, y, z + 1));
orangeGroup.attach(getIntersecting(rotationPointO, x, y, z - 1));
orangeGroup.attach(getIntersecting(rotationPointO, x, y + 1, z));
orangeGroup.attach(getIntersecting(rotationPointO, x, y - 1, z));
orangeGroup.attach(getIntersecting(rotationPointO, x, y + 1, z + 1));
orangeGroup.attach(getIntersecting(rotationPointO, x, y - 1, z + 1));
orangeGroup.attach(getIntersecting(rotationPointO, x, y + 1, z - 1));
orangeGroup.attach(getIntersecting(rotationPointO, x, y - 1, z - 1));
let rotation = Math.PI / 2
if (inverse) rotation = -Math.PI / 2
orangeGroup.rotation.x += rotation;
}
You can view a live example here.