How do I trigger code everytime my camera position changes?
This is what I have so far:
camera.addEventListener("change", function(event){
// my code
});
If you are using OrbitControls.js, to control the camera, then that library fires a change event when it's update function causes the camera to zoom, pan or rotate;
https://github.com/mrdoob/three.js/blob/master/examples/js/controls/OrbitControls.js#L203
So for example, you can use something like this to respond to when the camera moves;
function onPositionChange(o) {
console.log("position changed in object");
console.log(o);
}
controls.addEventListener('change', onPositionChange);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With