I've created some objects in my scene, and set up raycasting/tweening code so that whenever I click on an object, the object animates directly to the position and rotation of the camera.
This is my code for raycasting/tweening the object:
function onDocumentMouseDown( event ) {
event.preventDefault();
mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
mouse.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( scene.children );
if ( intersects.length > 0 ) {
new TWEEN.Tween( intersects[ 0 ].object.position ).to( {
x: 0,
y: 0,
z: -100 }, 2000 )
.easing( TWEEN.Easing.Elastic.Out).start();
new TWEEN.Tween( intersects[ 0 ].object.rotation ).to( {
x: 0,
y: 0,
z: 0 }, 2000 )
.easing( TWEEN.Easing.Elastic.Out).start();
object.lookAt.camera;
}
}
However, I was wondering, how can I make the tween animate the camera to the object, rather than the object to the camera? I want to do this because I want the objects to be constantly rotating and moving around the scene, and would like the camera to be able to stay on and track individual objects.
This is all in perspective camera, by the way.