c-frame / aframe-extras

Add-ons and helpers for A-Frame VR.

Home Page:https://c-frame.github.io/aframe-extras/examples/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Perform action as animation completes

Fatima-Aslam opened this issue · comments

I want to remove the 3D model as its animation completes/finishes. I try to use the "animation-finished" event but it removes the 3D model before the animation completes. Is there any parameter that calls the animation-finished event after a specific time? Please help me to fix this issue....
I use this code:

const button = document.querySelector('#play_again')
     const player = document.querySelector('#btn-obj')
     sound.play()
     player.setAttribute('animation-mixer', {clip: '*', loop: 'once', clampWhenFinished: 'true'})
     button.setAttribute('visible', 'false')
     player.addEventListener('animation-finished', () => {
       player.setAttribute('visible', 'false') })

And in HTML

<a-entity
      id="btn-obj"
      gltf-model="#Virgo-glb"
      scale="0.6 0.6 0.6"
      rotation="0 0 0"
      position="0 -0.9 0.2"
      new="clip: EsqueletoAction"></a-entity>

Would an additional setTimeout in the last line work?

player.addEventListener("animation-finished", () => {
  setTimeout(() => {
    player.setAttribute("visible", "false");
  }, "1000");
});