# Dynamic sound volume based on collision weight

I’m sure this is a very common game code, but I can’t seem to track anything down. I’m working on a bowling game and have attached a hit sound to the pins when they collide, but it’s always the same volume whether they are just plinking lightly together or getting bashed. It makes for incredibly unrealistic audio (here’s the sample: go to the end of the last alley and kick over the sample pins to hear it – https://playcanv.as/p/dBAIqENY/ )

So what do I attach to the script to change the sound volume based on the weight of the collision?

1 Like

On collision, you can check the total velocity of both objects and change the volume based on how high or low the velocity is.

If you want to go a step further, you can check the collision normal and compare that to entities’ velocity direction to get an idea of size the impact of the collision.

I agree with yaustar and would simply check the velocity of the ball upon collision. You can find the right scale value by some playtests.

@yaustar how would you use a collision normal vs entitiy velocity? That should probably give you the angle the pin should reflect to from the ball, which is probably not useful in scaling the sound.

I would project the velocity vector along the collision normal to see how much of it is actually in the direction of the collision. That would give me an idea of whether it was a head on collision or just a glancing hit.

1 Like

Hmm, but shouldn’t glacing and straight-on hits produce a sound of the same volume?

Edit:
Actually, probably not, at least in real life, as a collision surface would be of different size. Yes, good idea, could be used as an additional parameter in getting the final volume value.