I am using cube.add(camera) and camera.lookAt(cube)
So when i apply cube.rotation.y += 0.1 in a loop, it looks like cube is not rotating whereas floor is rotating.
And if i remove cube.add(camera) and camera.lookAt(cube) , then camera do not follows cube properly
camera settings:
const camera = new THREE.PerspectiveCamera(32, aspectRatio(), 1, 1000)
camera.position.set(30, 30, 30)

How can i achieve rotation like orbit control by applying cube.rotation

Hi!
Are you looking for something like that? [Solved] Smooth Chase Camera for an object

2 Likes

/cc

i posted it earlier there on stackoverflow . Later found forum of three.js . Is there anything wrong in this?

No, crossposting is allowed. We just link the thread at stackoverflow so itâ€™s easier to follow the whole discussion. And to avoid the situation where two people answer the same question at the same time.

When the camera is attached to the cube, it will follow the motion of the cube. In the case you are describing, that will look like the floor is rotating.

For orbiting around the cube, you will typically attach the camera to the scene or to no parent. Then you may move the camera in the animation callback function, and call camera.lookAt(cube.position) every time:

``````requestAnimationFrame( function animate(milliseconds) {
const seconds = 0.001*milliseconds;
const frequency = 0.5; //revolutions per second
const omega = 2*Math.PI*frequency;
camera.position.set(30*Math.cos(seconds*omega), 30, 30*Math.sin(seconds*omega));
camera.lookAt(cube.position);
requestAnimationFrame(animate);
});
``````

i used your solution, with that complete scene is rotating.I actually needed a third person camera and tried the following solution which worked like needed( donâ€™ know how good/bad the solution is)

I didnâ€™t either add camera to cube or camera to scene.And didnâ€™t use camera.lookAt function.

I just add a orbit control
and in callback loop i set the x and z of camera
camera.position.x = 30+car.position.x;//30 is default position of camera
camera.position.z = 30+car.position.z;

and added controls.enabled=false to prevent zooming and rotation by mouse

You add OrbitControls, let them update once, then disable them. That is basically the same as using `lookAt` once. Note that in your original post, you used `lookAt(cube)`, which is incorrect. Should be `lookAt(cube.position)` if camera is in world space. Otherwise, whatâ€™s different with your new solution, is that you will follow the car from the same direction all the time, when the car rotates. And if your car runs uphill or downhill, the camera will stay on the same level constantly, since you donâ€™t follow on the y coordinate. But if this is what you intended, then I am happy you found a solution.