Imagine you have an object called object1 (which is of type THREE.Object3D()
) and you've set its initial position like this:
object1.position.set( 1, 2, 3 );
var position2 = new THREE.Vector3( 11, 12, 13 );
Now, if you want object1 to smoothly move to position2,
You can make use of the tween.js library and create a transition between the two positions:
setupObjectPositionTween( object1, object1.position.clone(), position2,
2000, 100, TWEEN.Easing.Linear.None ); // duration, delay, easing
by employing:
function setupObjectPositionTween( object, source, target, duration, delay, easing )
{
new TWEEN.Tween( source )
.to( target, duration )
.delay( l_delay )
.easing( l_easing )
.onUpdate( function() { object.position.copy( source ); } )
.start();
}
UPDATE:
Don't forget to include the following in your animation loop:
TWEEN.update ();
and within the init() function:
TWEEN.removeAll(); // clear out tween buffer