I am facing an issue with the three.js built-in lookAt() method related to my hierarchical Object structure setup.
var obj1 = new THREE.Object3D();
obj1.position.x=200;
obj1.rotation.x=0.1;
scene.add(obj1);
var obj2 = new THREE.Object3D();
obj2.position.y=-400;
obj2.rotation.y=0.21;
obj1.add(obj2);
var obj3 = new THREE.Object3D();
obj3.position.z=-200;
obj3.rotation.x=0.1;
obj3.rotation.y=-0.1;
obj2.add(obj3);
When I use
obj1.lookAt(camera.position);
it works correctly. However, when I call the method from a child object, like
obj3.lookAt(camera.position);
the rotation is incorrect.
Considering that the rotation of the parent object might be causing the issue, I attempted to convert the world position of the camera to the local position of the object without success.
var vector = new THREE.Vector3();
vector.setFromMatrixPosition( camera.matrixWorld );
obj3.lookAt( obj3.worldToLocal( vector ) );
Any assistance on this matter would be highly appreciated.