Object Collision Sound Effects

This thread is designed to provoke discussion and contribution, so that we can collectively design an optimal solution. No promises, but I’ll likely end up open sourcing a module that uses what we come up with.

I want to create a system to add dynamic sound effects when objects collide. It should preferably take relative velocity, material, and mass into account when determining the sound being played.

First, let’s break the problem down into chunks.

  • Detect collision
  • Calculate various parameters
  • Play determined sound

Now that we know exactly what we need to do, let’s discuss how we could do it.

I’ve come up with multiple possible methods, but I’m uncertain which is best, and I’ve run into some annoyances as well. Some are clearly worse than others, but I’m putting them here for sake of completion. Note that I have not attempted to program any of these yet, they are simply ideas for now.

Method A:
Detecting sudden changes in current velocity could indicate when a collision has occurred. Sudden stops and starts, etc. The amount changed would tell us the strength of the hit, so we could alter the volume of the SFX accordingly, giving a more dynamic feel.
Problem is, it would likely lead to false positives, doesn’t give us material data, and requires us to track and store velocity in order to know when collisions have occurred.

Method B:
Use :GetTouchingParts() and detect new entries as collisions. Calculate the relative velocity and total mass of the two objects for volume. Have sounds for MaterialA+MaterialB and play the sound that matches the two materials. This one would require constant polling, but it would give material data that the previous method could not. (Although the materials are a problem discussed further down)

Method C:
Using the .Touched event. When touched, calculate the relative velocity between the hit object and the main object, and use that to determine volume. You can also weigh in the combined mass of the objects in your volume calculation. Have sounds for MaterialA+MaterialB and play the sound that matches the two materials.

I’m sure most of you instantly thought of this, as did I, but the context of my game brings up a separate issue, and this issue is what led me to even start this post in the first place.

My game uses Textures, rather than the default Roblox materials. They’re often just set to Fabric to remove shine and highlights. Therefore, calculating the parameters becomes more complex. I need to mark the objects with custom metadata, and I’m uncertain what the best way to go about this is.

We could use Attributes (jk, they’re coming soon™), CollectionService Tags, ValueObjects, or a part naming system which we do some string manipulation on.

All of these require me to manually set up hundreds upon hundreds of parts in my game by hand, which I want to avoid. Also, using part names to indicate properties would lead to a messy workspace.

What do you guys suggest?

14 Likes

Mixing method A and Method C;
Track the velocity and use .Touched to remove false positives. You can only play the sound once a .Touched has been triggered and the calculations post-collision have been made.
You can now use the information gained via .Touched to figure out things like impact angle; if your moving parts velocity can be seen as perpendicular to the plane we’ve collided with, we know thats going to give a bassier sound than a velocity that can be seen as near parralel.

An added bonus of figuring out the plane we’ve touched is that those planes correspond to a face! Whats on those faces? Textures! You’re now able to do a texture check (instead of checking what the part’s name is or the tags for a part) and check the textureID in a table, containing textureIDs and their relative properties. If you ever needed to, you could have hard/soft sided walls using this.

Alternatively, unless you’re creating a ton of parts at any given instance, CollectionService might be the way to go with assigning pseudo-material. It sounds daunting to do it all by hand, so I’d really recommend looking at the Tag Editor by sweetheartichoke to ease that, just create your materials as tags, find all the parts you need and complete it all at once.

8 Likes

So, i not really have much experience with collision, but why not use the .Touched event as @edenojack has say, then calculate the vertex of both objects and if they intersects then play the sound? Hope this can help🙂

1 Like