How can I make 'hit sounds' for when a ball hits another part?

I am trying to add some sounds when a ball hits certain materials. What is the best way to detect when the ball hits a brick or some terrain?

3 Likes

Hiya!
Need two things to do this reliably. You need collision information and you need the objects acceleration immediately after a collision to guess how big the hit was.

You can get the first bit by using OnTouch and OnTouchEnded. These routines are a bit fiddly in roblox and require manual reference counting to do a good job.

Eg: the first time you see a collision between two parts is a good time to play a Sfx, and increment and decrement as you see touches begin and end. Lua dictionarys ftw.

You also need to calculate the objects acceleration, which you can do by tracking an objects velocity frame by frame. The difference is accel. If your object gets a touch and also has a big change in accel, make a noise.

9 Likes