I'm trying to keep an object (a sphere) centered in front of a camera as the camera moves around. I'm animating the camera by changing it's position and it's rotation with lookAt()
which seems to work correctly. But the sphere object just won't say in the frame. I've tried
const centerSphereInCameraWithQuaternion = (sphere: THREE.Mesh, camera: THREE.PerspectiveCamera) => {
const vec = new THREE.Vector3( 0, 0, - 4 );
vec.applyQuaternion( camera.quaternion );
sphere.position.copy( vec );
}
which causes the sphere to disappear entirely. I've also tried
const centerSphereInCamera = (sphere: THREE.Mesh, camera: THREE.PerspectiveCamera) => {
sphere.position.copy( camera.position );
sphere.rotation.copy( camera.rotation );
sphere.updateMatrix();
sphere.translateZ( - 4 );
}
which almost works, but the sphere rotates in the opposition direction of the cameras facing. Also tried
sphere.position.sub(camera.position);
which doesn't show anything at all.
I've tried adding a camera helper to make sure the camera's world matrix is being updated correctly, and it seems like it is.
What am I doing wrong here? Is there a way I can accomplish this without adding the mesh as a child of the camera?