Play sound on collision

How to add sound for Collision. Mine doesn’t work.

Hi @ETHAN_FOX_CRISTOBAL! Can you show your setup please?


Hi @ETHAN_FOX_CRISTOBAL,

You need to add a collision component that acts as a trigger. You can study this tutorial that does exactly that: Collision and Triggers | Learn PlayCanvas

If you use this.entity.sound.play() you have to make sure the entity with the script has the sound component. (So not a child entity).

1 Like

Apart from that, the slot name is crashSound while use you CrashSound in your script.

tried it but it doesn’t work, it only works when my character is deployed not when destroying the coin

If you share a link of your project someone can take a look.

https://playcanvas.com/project/974652/overview/ball-dozers_finalproject_inc
https://playcanvas.com/editor/scene/1513697

here you go

There is no sound component on the entity with the script. If you use this.entity.sound.play() you have to make sure the entity with the script has the sound component. Right now the sound component is on a child entity.

What do you mean child entity?

Hi, how do I do that and I cannot tell which one is a child entity.

image


well it’s there the spelling is correct but it doesn’t work. still not focused on the collision (with the coins).

Because you try to play a sound on this.entity and this.entity is always the entity with the script. In your case this is your Mike entity. So try to attach the sound to your Mike entity.

1 Like