Animation in a loop

Hi,

I want to animate an object in a while loop, can someone help me?

I want samething similar as:

while( currentDistance < distance ) { 

    object.position.x += 0.01 

}

Cheers

1 Like

The problem with using a while loop like that is that you shouldn’t move the object continuously — just once every frame. To do that you can use requestAnimationFrame, or renderer.setAnimationLoop. For example:

renderer.setAnimationLoop( function () {
  if ( currentDistance < distance) {
    object.position.x += 0.01;
  }
  renderer.render( scene, camera );
} );
3 Likes

Thanks mate