Rotate camera to point

In my example I have box at 0,0,0 and camera at -30, 0, 50. How can I rotate my camera to box position? I tried camera.lookAt but after this, camera just moved at 0,0,0, not rotate.

Summary

codepen
what I have : https://i.imgur.com/KKWeepU.png
what I want : https://i.imgur.com/Izzc2l2.png

Use OrbitControls and set the target to (0, 0, 0) https://threejs.org/docs/#examples/en/controls/OrbitControls

When i add OrbitControls it drops camera position :frowning:
codepen

const controls = new THREE.OrbitControls( camera, renderer.domElement ); controls.target.set(0,0,0)

OrbitControls.target is the zero vector by default so your suggestion has no effect.

Can you please try to clarify your question? I’m afraid “rotating to a position” does not make sense.

Besides, you are using three.js files from different releases. Meaning OrbitControls from R85 and three.min.js from R110. Please never do this. Such combinations are not supported.

2 Likes

I don’t think it drops the camera position. It would be just appearing as though it has dropped the position because it is looking at the origin.

Doing console.log(camera.position.x) confirms it.

Also, always do controls.update() after transforming the camera.

I’m just learning and testing three.js, so first of all, sorry for my possibly incorrect questions.
I wanna create moving like this
At the beginning I have box and camera in front of it and then I want to move the camera so that she continues to look at the box. In this situation have I move and rotate camera, or move and rotate everything else except the camera?

In the render loop do this:

t = Math.min(t + 0.01, 1);
camera.position.copy(startPosition).lerp(endPosition, t);
camera.lookAt(0, 0, 0);

If you are just starting out, then this should be okay.

1 Like

Thank you very much for your help, but apparently I yesterday somewhere made some small mistake in the code, and because of this, everything did not work as intended. Now, when I changing camera.position everything works as expected codepen

1 Like