I've been experimenting with making a Boxgeometry float in three.js, but my attempts have not been successful so far. I tried using setTimeout to achieve the floating effect, but it didn't work as expected. Here is what I attempted:
function animate() {
requestAnimationFrame( animate );
cube.position.y += 0.01
setTimeout(function(){
cube.position.y += -0.02
}, 10000);
renderer.render( scene, camera );
}
Instead of smoothly floating, the cube just moves up and down in a choppy manner.
Can anyone suggest a better way to create a smooth floating animation for the cube?