Rotating object constantly and with mouse

Viewed 41

I have a cube, that I would like to be constantly rotating, but I should also be able to rotate it using mouse. So far I am able to do this seperately, but I don't know how to make the cube countinue rotating also after moving it with mouse.

This is the automatic rotation:

group.rotation.y += 0.002;

This is the code to rotate it using mouse:

function render() {
        
     //horizontal rotation   
     group.rotation.y += ( targetRotationX - group.rotation.y ) * 0.1;
        
     //vertical rotation 
     finalRotationY = (targetRotationY - group.rotation.x); 

    if (group.rotation.x <= 1 && group.rotation.x >= -1) {

        group.rotation.x += finalRotationY * 0.1;
    }
    if (group.rotation.x > 1) {

        group.rotation.x = 1
    }
    else if (group.rotation.x < -1) {

        group.rotation.x = -1
    }

        
        renderer.render( scene, camera );

}

This is a demo: https://miag676.github.io/

0 Answers
Related