5

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

Matías Cánepa
  • 5,770
  • 4
  • 57
  • 97

1 Answers1

5

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

Mugen87
  • 28,829
  • 4
  • 27
  • 50
  • how to do this if im not using `OrbitControls`? – oldboy Aug 12 '23 at 06:51
  • When not using `OrbitControls` you can just translate the camera. The orientation is not automatically changed. – Mugen87 Aug 12 '23 at 08:21
  • hm i tried translating the camera but didnt have any affect. maybe something in my code conflicting? i just centered the actual blender model which was the issue for me anyways – oldboy Aug 14 '23 at 01:21
  • I suggest you ask a new question for this or post at topic at the [three.js forum](https://discourse.threejs.org/). – Mugen87 Aug 14 '23 at 08:42
  • now its working, but i have created a new question for something else. can you take a look at [my question here](https://stackoverflow.com/questions/76909252/measure-from-model-to-frustrum-edge-to-adjust-camera)? – oldboy Aug 16 '23 at 03:32