As I try to animate a cube in my scene, I keep encountering an error that reads: "TypeError: Cannot read property 'rotation' of undefined."
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
var time = Date.now() * 0.005;
camera.position.x += ( mouseX - camera.position.x ) * 0.05;
camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
camera.lookAt( scene.position );
for ( i = 0; i < scene.children.length; i ++ ) {
var object = scene.children[ i ];
if ( object instanceof THREE.PointCloud ) {
object.rotation.y += 0.01 ;
}
}
cube.rotation.y = time* 0.01;
renderer.render( scene, camera );
}
The PointCloud element works smoothly, however when it comes to the cube animation, I get the mentioned error.
Any suggestions on how to troubleshoot and resolve this issue would be greatly appreciated.