how move camera up without tilting in three js

Viewed 270

I would like to pan the camera up when the render starts. In the official documentation, in order to move away from the placed cube, we adjust the z axis

camera.position.z = 5

Now, I want to pan up just like when I drag with the right click using orbit controls. But the result is that the camera tilts down. I'm using

camera.position.y = 5

To better understand the situation here are some references loooking at the scene from de side:

This is the initial set up

This is the initial set up

this is when I set camera.position.z = 5

this is after setting camera.position.z = 5

This is when I set camera.position.y = 5 (not what I had in mind)

This is when I set camera.position.y = 5

This is what I want

This is what I want

1 Answers

When using OrbitControls, the camera always looks at a target point. The default value of this target is (0, 0, 0). If you want to lift the camera and still want a straight look direction, you also have to adjust this target vector:

controls.target.y = camera.position.y;
controls.update(); // might be necessary to update the controls

three.js r116

Related