Setting distance of OrbitControls

Hello! I’m looking through the code for the OrbitControls script, but I can’t find a way to set the distance of the camera from its target manually, only the min and max distance that the user can view the target from. I’d like this feature in order to reset the zoom when switching between viewable objects for an app I’m making.

Original Post on Discord

by user 224300406682025985

Hello, you can set the camera target position / camera position by calling ‘setCameraTarget’ with a position in localspace and true to set the position immediately.
(The method name is not ideal, it refers to the target position where the camera should move to and not of that of the look target, that is ‘setTarget’)

If you want a specific distance you have to calculate that in your code by e.g. storing the start position/direction and length depending on what exactly you need

Sweet! That did the trick, thanks

by user 224300406682025985