# Set the volume of a collision sound, based on the force of collision? [SOLVED]

Member, PRO Posts: 29
edited June 2017

## this is a tough one...

I'm creating a physics game which you must lower the golden block to the base of a tower. I didn't add any sounds up to this point, but I recently added sound effects to my clickable squares so they make a hitting sound when the collide with one another. Here are a few screenshots of what I'm describing:

# #

As you can see I added my own variation for the time being by having the rules when it collides, has a combined speed (motion.x+motion.y) less than -200 (because they are falling), and self.already playing sound is false.... it will proceed to play the sound.

I'm wanting to know what goes in the red VOLUME equation I outlined.

I tried a few but the failed, but here are a few things to take into consideration:
1. Volume can only range from 0-1
2. It would make sense to have self.motion.x and self.motion.y in the equation... although self.motion.x can be taken out because it is a downward scrolling game.
3. self.motion.y will always be negative. Again, downward scrolling game. This negative makes it harder to convert the speed to the 0-1 range.

If you can figure it out you have some God-like math skills!
All replies are appreciated! Thanks!

• London, UK.Member Posts: 12,822

abs(magnitude(Linear motion X, Linear motion Y))/200

• London, UK.Member Posts: 12,822

P.S. you might have to change the '200' value to find better range.

• Member, PRO Posts: 29

Works like a charm! Forgot all about the absolute value and magnitude functions. duh! I just added a min(x,y) to make it cap off at 1:

### min(abs(magnitude( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y )/300),1)

Thanks, that's just what I wanted

• London, UK.Member Posts: 12,822

@xD.Enterprises said:
I just added a min(x,y) to make it cap off at 1

You don't really need to do that, you can save your app an unnecessary calculation as the volume won't (can't) ever go above 1.

• Member, PRO Posts: 29

Ok, I'll delete it because this actor has many many copies on the screen, which every less calculation will add up to make a difference in performance.