Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
Slow animation of Three.js object on event, while maintaining current position

I'm trying to slow the animation of a rotating cube on mouseOver, and have it continue on mouseLeave.

Currently when the mouse enters the cube, it slows down, but also snaps to another rotation quite suddenly, before snapping back when the mouse leaves.

Can anyone advise me on how to achieve a smooth slowdown transition without the snapping? A gradient would also be very nice, similar to css animations. My code is below.

let rotationSpeed = 0.9;

const interaction = new Interaction(renderer, scene, camera);

cube.cursor = "pointer";
cube.on("mouseover", () => {
    rotationSpeed -= 0.5;
});

cube.on("mouseout", () => {
    rotationSpeed += 0.5;
});

// CLOCK

const clock = new THREE.Clock();

const tick = () => {
    // targetX = mouseX * 0.001;
    // targetY = mouseY * 0.001;

    const elapsedTime = clock.getElapsedTime();

    // Update objects
    cube.rotation.y = rotationSpeed * elapsedTime;
    cube.rotation.x = rotationSpeed * elapsedTime;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

"mouseover" event subtract many times -0.5 to 0.9, then the "rotationSpeed" value change to negative. So, try:

cube.on("mouseover", () => {
    if(rotationSpeed > 0){
     rotationSpeed -= 0.1;
    }
    
});

cube.on("mouseout", () => {
    rotationSpeed = 0.9;
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda