yomotsu / camera-controls

A camera control for three.js, similar to THREE.OrbitControls yet supports smooth transitions and more features.
https://yomotsu.github.io/camera-controls/
MIT License
2.05k stars 256 forks source link

Camera rotate on its y-axis #535

Open SoraVN98 opened 3 months ago

SoraVN98 commented 3 months ago

Is your feature request related to a problem? Please describe.

I want to my camera rotate on its own y-axis like pan movement (not truck) . I try to use rotate function but it seems like the camera move around the target.

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

yomotsu commented 3 months ago

Thanks for using camera-controls. Unfortunately, that is intentional. Camera-controls is a library designed for orbit rotation controls.

Remi-Tribia commented 3 months ago

Try to position the target just in front of the camera (1cm). Now if the camera orbits the target, it will have the same effect as if the camera were spinning on its axis.

You can calculate target position depending on camera position like so:

const calculateTarget = (camera: PerspectiveCamera, distance = 0.01): Vector3 =>
  (new Vector3()).addVectors(
    camera.getWorldPosition(new Vector3()),
    camera.getWorldDirection(new Vector3()).multiplyScalar(distance)
  );