Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Three.js point camera at fixed coordinate

In Javascript THREE.js, given the coordinates of the camera and the coordinates of a point (x, y, z), how would I rotate the camera to look directly at the point?

like image 374
hyper-neutrino Avatar asked Nov 28 '25 05:11

hyper-neutrino


1 Answers

You can make the camera "look at" a world-space point by using the lookAt() method, like so:

var point = new THREE.Vector3( x, y, z );

camera.lookAt( point );

Note: This method is limited, in that it will not work correctly if the camera is a child of another rotated or translated parent object. However, if the camera has no parent, or if the camera is a child of the scene directly, then the method will work as expected.

three.js r.71

like image 180
WestLangley Avatar answered Nov 29 '25 20:11

WestLangley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!