# Play sound only on collision with certain object

**URL:** <https://forum.playcanvas.com/t/play-sound-only-on-collision-with-certain-object/41690>\
**Category:** Help & Support\
**Tags:** editor, scripting, physics\
**Created:** [January 13, 2026, 6:18pm UTC](https://forum.playcanvas.com/t/play-sound-only-on-collision-with-certain-object/41690 "2026-01-13T18:18:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aksel\_Walztoni](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/aksel_walztoni/32/37413_2.png) [@Aksel\_Walztoni](https://forum.playcanvas.com/u/Aksel_Walztoni)\
**Post date:** [January 13, 2026, 6:18pm UTC](https://forum.playcanvas.com/t/play-sound-only-on-collision-with-certain-object/41690/1 "2026-01-13T18:18:45Z")

</div>

I have a scene with SpongeBob, a basketball, and a player. SpongeBob says “Hi! i’m SpongeBob!” when I touch him as a player, but also plays the noise when the basketball touches him. This gets annoying fast, is there any way I could make it so SpongeBob only plays the noise when the player hits him?  
Here’s my code:

```javascript
var Collider = pc.createScript('collider');

// initialize code called once per entity
Collider.prototype.initialize = function () {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};

Collider.prototype.onCollisionStart = function (result) {
    if (result.other.rigidbody) {
        this.entity.sound.play("hit");
    }
};

```

---

<div class="post-metadata">

**Author:** ![Codeknight999](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/codeknight999/32/36586_2.png) [@Codeknight999](https://forum.playcanvas.com/u/Codeknight999)\
**Post date:** [January 13, 2026, 6:57pm UTC](https://forum.playcanvas.com/t/play-sound-only-on-collision-with-certain-object/41690/2 "2026-01-13T18:57:58Z")

</div>

Hi @Aksel_Walztoni!  
You can acess the entity you hit’s whole data, including name, if you add  
`&& result.other.name === "Name"`  
or  
`&& result.other.tags.has("someTag") `  
to filter just for that tag.

---

<div class="post-metadata">

**Author:** ![system](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/9/f/9f42d319539b35306476fd0ef3f95e4ea61b0840.png) [@system](https://forum.playcanvas.com/u/system)\
**Post date:** [April 10, 2026, 3:27pm UTC](https://forum.playcanvas.com/t/play-sound-only-on-collision-with-certain-object/41690/3 "2026-04-10T15:27:06Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
