Gunshot as camera goes through a wall?

I’m trying to have an sfx played as the camera goes through a wall, but the sound repeats every frame if the camera sits in the intersection, instead of one single gunshot and if the user goes back, one gunshot again.

https://playground.babylonjs.com/#8Z0MKW#3

Is there any other way of doing this?

Something like this ? https://playground.babylonjs.com/#8Z0MKW#4

2 Likes

Exactly like that. Super thanks :smiley:

Do you know by any chance if I can load more gunshot files, and play them randomly so that is not the same gunshot?

yes, just create a few of them, put them in a array and use a random value for the array index :slight_smile:

I don’t think I understand what you mean, never used an array and can’t find any documentation

Is it SmartArray?

Something like this (just a normal javascript array) https://playground.babylonjs.com/#8Z0MKW#5

1 Like

I’ve noticed that if I rotate the wall, the intersection point messes up.
https://playground.babylonjs.com/#8Z0MKW#6

Is it the bounding box? How can I update it?