The Objective
My aim is to create a straightforward camera zoom in animation that increases the zoom level by a specific amount each time the button is clicked.
The Current Status
I have successfully implemented the animation using Three.js and linked it to buttons to trigger the script.
function cameraZoomIn() {
console.log("Camera Zoom In Function Clicked");
camera.position.z -= 50;
requestAnimationFrame( cameraZoomIn );
render();
};
<input type="button" onclick="cameraZoomIn();" value="Zoom Camera In!" />
The Issue at Hand
Although the animation is functioning, it continues to loop indefinitely when clicking on the "Zoom Camera In" button -
Update 1
If I eliminate requestAnimationFrame
, the animation runs only once but abruptly jumps to the target position instead of smoothly transitioning. What could be causing this repetitive looping behavior?