Camera position & target in OrbitControls

I am using OrbitControls and I want to position the camera and the point it is looking at.

I adjust my camera Y position to move it up whilst keeping the camera lookAt and the controls target pointed at the middle of my object. In the Fiddle I made (Edit fiddle - JSFiddle - Code Playground) adjusting the camera Y appears to move the object further away

I’m sure I have made a typo somewhere - can someone point out my error or mistaken assumption?

This is where things go wrong:

controls.minPolarAngle = Math.PI / 2;
controls.maxPolarAngle = (1 * Math.PI) / 2;

try to comment this piece out and it will work as intended

Perfect - that works - thank you.

Is there a way to continue to restrict the rotation to a single axis along Y too?

restrictions by themselves work, you can set, say

controls.minPolarAngle = Math.PI / 4;
controls.maxPolarAngle = Math.PI / 4;

or, in a similar way, min/maxAzimuthAngle

The problem is, in you case, when you change the camera height, independently of controls, it also changes polar angle and things will not work correctly if the angle goes outside the range that controls supposed to handle.

I’m not sure what is the reason to use both GUI and controls at the same time.

You could do your own calculations and restrict GUI, so it doesn’t produce angles outside a certain range or set angles instead of heights and sync with orbit controls settings but that sounds too complex, maybe there is an easier way to do what you are trying to.

GUI is only used in this Fiddle to illustrate the problem.