Play sound component with animation using A-Frame

2.4k views Asked by At

I'm trying to build an A-Frame scene where a car drives by the user, and I need the sound of the car to start playing as the car starts moving. For example:

<a-collada-model id="car" src="#car-dae" position="-0.7 0 -100" rotation="0 90 0">
  <a-animation attribute="position"
         dur="7000"
         begin="model-loaded"
         fill="forwards"
         to="-0.7 0 20"
         repeat="0"
  ></a-animation>
</a-collada-model>

Can I put a sound component on the animation? If not, how should I go about having the sound play at the same time as the animation? I tried putting the sound component on the collada model and gave it a on:model-loaded (same event as the animation), but this never played the sound. In fact, the only way I seem to be able to get the sound to play is using autoplay. Any ideas?

If it helps, all of my code is in this git repo under carChase.html

https://github.com/zeekw/aFrameTests

1

There are 1 answers

2
ngokevin On BEST ANSWER

Did you try putting the sound component on the model, or as a child of it?

<a-collada-model src="#car-dae" sound="on: model-loaded; src: #car-sound">