In my game, I am struggling to make the camera always face the back of a helicopter as it rotates. Despite my efforts, I can't seem to synchronize the camera's movement with that of the helicopter. You can see an image of what I'm aiming for here, and what is actually happening here.
The camera is initialized using the following code: const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
function cameraUpdate(camera) {
camera.position.x = movingObject.x + 20
camera.position.y = movingObject.y + 20;
camera.position.z = movingObject.z;
camera.lookAt(movingObject.position);}
This function is called within my render loop, where 'movingObject' represents the helicopter. The rotation logic for the helicopter is found in my inputController function which is also called in the render loop. Here is the snippet of the rotation code:
if (input.rotClk === true) {
moveableObj.rotatation.y += -0.05;
}
I attempted to adjust the camera rotation by adding "camera.rotation.y += -0.05", but this did not yield the desired outcome.