Move Camera with new orbitControls Target

Hello,

When I set a new target for orbitControls, the camera stays where it is. Is there a way for the camera to keep its relative position to the orbitControls’ focus point (target)?

Im calling orbitControls.target.set(0, 0, 1) to set a new target, but I’d like the camera position to follow it as well and maintain the orientation. I was trying to use camera.position but I can’t get the math right. Is there an easier way?

Thank you for any responses!

@max

You could create a new object 3d and set position to 0,0,1, then set target of orbit controls to object1.position.x y and Z in update loop now when you move the object the camera should track the object, you can then use a second new object added to object 1 with position set to object1.position.x, y, z-1, object2 will now stay relative to object1 and you can set the camera position to object2.position.x,y,z…

I like that. I’ll give that a try. While I waited for a response, I ended up getting the math to work out. But it’s a lot of lines… Thank you for that suggestion.