Dubstep Guns - 17/03/20

Back to Main Page

I was watching youtube one night when it recommended me the old video by Corridor Digital, Dubstep Guns:

I immidiately started thinking about how I could create similar gun effects in Unity, that synced with music. I had previously researched the WAV file format for a previous project, but I wasn't sure if it would be the best way of doing it.

After a little googling, I found that you could get the average volume from a section of audio from an audioclip, by loading the data from the clip, reading the absolute values and averaging them. I thought that this would be promising, but I wasn't sure how I could sync it up to the audio currently playing.

I also wasn't sure how I would extract the individual frequencies from the track. I had done a little experimenting with calculating the fast fourier transform of audio before, at the same time when I was learning the wav file format, but I never managed to get it working correctly.

The next day, I found out about AudioListener.GetSpectrumData(). This can be passed an array of floats, which will be populated with the volumes for the different frequencies. I could then use this to trigger emissions of particle systems when the volume of a specific frequency went above a level.

I then used that particle system to make a quick proof-of-concept shooter, by making the individual particles do damage, and tried to find a Klaypex song that wouldn't immidiately give me copyright violations if I used it. I'm pretty sure the song I used, Jump, is royalty free, however some websites seemed unsure.

I then created a quick environment with Unity's new Snaps packs, added in some blood effects, and made them spawn infinitely, giving this final result. The blue mainly reponds to low tones, such as bass drums, while the yellow and red respond to slightly different frequencies in the treble range.

There are still a couple of problems with this setup, because of harmonics. In rich tones, there will also be harmonics which trigger the system at higher frequencies. This causes the particles to sometimes trigger when they shouldn't. My design for the actual particle systems also wasn't great, but then again I'm not a designer, and it was the best I could do quickly.

The unity project can be downloaded here

Back to Main Page