Three.js requestanimaframe

Have some problem.

const mesh = new THREE.Mesh(geometry,material);
let speed = 0.05;

 const animate = function () {

 requestAnimationFrame( animate );
 mesh.rotation.x += speed;
 

 renderer.render( scene, camera );

};

I want to gradually reduce the speed in requestAnimationFrame
speed should decrease 0.01
0.04 ,
0.03,
0.02,
0.01,
0

the only thing I came to is
but in this case it decreases mesh.rotation.x but not speed

document.addEventListener(‘click’, function () {
speed *= -1;
})

need a solution similar to speed = 0.05 -=(0.01);

I’m not 100% sure I understand, but wouldn’t this work :face_with_raised_eyebrow: ?

const animate = function () {
  requestAnimationFrame( animate );

  mesh.rotation.x += speed;
  speed = Math.max( 0, speed - 0.01 );

  renderer.render( scene, camera );
}

this does not reduce the speed, but immediately equates it to zero

template for solution

Well, it does it reduce the speed over 5 frames as you asked (if you’d like it to decrease slower, it should be enough to decrement with a lower number, ex. 0.001.) :man_shrugging:

thanks,my bad.