Collision & Sounds

For some reason, my collision and sound aren’t working correctly. Instead of destroying the object, it just bumps into my character and the sound doesn’t play.

Hi @Pixels and welcome,

To check the name of the entity that collided you need to do this:

if(result.other.name === 'key'){

I already changed the code, but it still doesn’t work.

Can you share your project or a sample project that reproduces the issue to take a look?

https://playcanvas.com/editor/scene/1592424

Your script type is collisionAssets in the scripts source code.

But on the Animated Sprite entity you have a script attached name collision. Most likely that’s an older reference, ultimately your code isn’t executing. I’ve tried adding some breakpoings and they never fire:

To fix that, remove the collision script from your player and parse your script asset using this button:

Now you can go and attach the collisionAssets script to your player entity.

The collision worked, but the sound is still not playing.

You don’t have any sounds attached to your player entity. Add a sound component with the right slot named ding and it will work.