Camera zoom in and out

You’re only ever setting the x axis of newPosition, you’ll need to do as @prisoner849 has suggested but add / subtract from the x and z position based on a camera “right” or “left” world direction eg something like…

const moveLeft = () => {

  let dir = new THREE.Vector3();
  camera.getWorldDirection(dir);

  const left = new THREE.Vector3();
  left.crossVectors(camera.up, dir).normalize();

  newTarget.add(left)
  newPosition.add(left)
}

const moveRight = () => {

  let dir = new THREE.Vector3();
  camera.getWorldDirection(dir);

  const right = new THREE.Vector3();
  right.crossVectors(dir, camera.up).normalize();

  newTarget.add(right)
  newPosition.add(right)
}

this is untested psuedo code and not complete ( i may have missed some steps in calculating the left and right vectors ( see this post by @prisoner849 ) and you may also want to use left.multiplyScalar(amount) to increase the amount to be moved ) but should put you in the right direction as to what you need to achieve…

1 Like