Beginner Question: Using a For Loop to add multiple cubes that all animate

You keep overwriting your cube in the loop. Use an array and you can address each cube via the index.

 var cube = [];
...

for (let i = 0; i < 3; i++) {
    cube[i] = new THREE.Mesh(geometry, material);
    cube[i].position.x = i;
    scene.add(cube[i]);
  }
...
function render() {
  cube[0].rotation.x += 0.01;
  cube[0].rotation.y += 0.01;
// use other indexes....
  renderer.render(scene, camera);
}

:slightly_smiling_face:


Check this out too:
https://hofk.de/main/discourse.threejs/2019/Carousel/Carousel.html
from

1 Like