How do you instantly stop/freeze OrbitControl's effect on camera rotation?

I have OrbitControls enabled on my camera. However, I need a way to be able to instantaneously freeze/stop the camera rotation at any point.

cameraControls: function(val) {
		this.controls.rotateSpeed = val ? 1 : 0;
		this.controls.enabled = val;
		this.controls.enableRotate = val;
}
test.cameraControls(false);

This only stops the controls from further rotation. But if my camera is still rotating and decelerating as a result of a recent mouse drag, it still continues to rotate until fully decelerated.

What I need is a way to instantly stop the rotation exactly where it is, the moment I call the function. I thought setting rotateSpeed to 0 would help, but it doesn’t.

You you use vanilla JS, this might help a bit:

So the only way to stop it dead is to kill it completely :laughing: Gross, but thanks!

1 Like

I’m not aware of any other method besides modifying the source code of the OrbitControls.js itself.

You can set the controls orbit autoRotate boolean to false using an event listener when starting the interaction with the orbit controls.
To make it more fancy you can start the autoRotate again after a certain time.

Don’t forget to call the controls update function in the animation loop.

See this code:

    controls.autoRotate = true;
    controls.autoRotateSpeed = 4.0;

    let timeoutID = undefined;
    controls.addEventListener("start",()=>
    {
        //Clean an existing timeout first
        if(timeoutID != undefined)
        {
            clearTimeout(timeoutID);
            timeoutID = undefined;
        }

        //Stop the auto rotation
        controls.autoRotate = false;

        //Start the auto rotation again after 3 seconds
        timeoutID = setTimeout(function()
        {
            controls.autoRotate = true;
        }, 3000);
    });