Rotating the camera without moving away from the object

I am trying to rotate the camera on button click (something like 360-degree rotation), I want to rotate the camera in the same direction regardless of its position. I was able to achieve this by applying camera.translateX() in the animation frame. Since I’m using translation, the camera moves away from the object after a few seconds. Is there a way in which I could keep the distance between the camera and the object the same?


something like this? amazing-lake-n5yjgt - CodeSandbox

const t = clock.elapsedTime
const r = 5
camera.position.set(Math.sin(t) * r, 0, Math.cos(t) * r)
camera.lookAt(0, 0, 0)

btw you know you can also just rotate the object, or the group it’s in, that is often easier than having to deal with translation math.

but rotating the group will be only in a single direction if move the camera the direction of rotation changes