Search code examples
objectcamerathree.jsresetscene

Three.js camera, object and scene origin when moving object


I can not figure out how to set the object to the three.js scene origin after having moved it. What happens is that I built a scene with an object at the origin and a camera pointing at it. I am using the mouse to move around the object in the scene. Then I try to reset the object position so that it goes back to the scene origin like that with the camera pointed at it:

camera.position.x = 10;
camera.position.y = 10;
camera.position.z = 10;
camera.lookAt( scene.position );
group.position.set(0, 0, 0);

I seems fine at first. But when I try to rotate the camera with the mouse around the object, the object shifts back to its previous position and the camera is not centered around it.


Solution

  • I was using controls. Just do this:

    controls.target.set( 0, 0, 0 );