- Home /
How to reflect / bounce audio off of a 3D Object?
I'm working on a project that will require an audio source (emitter) and an audio listener (the player) -- Easy. What I need is the ability to bounce / deflect / block an audio emitter based on 3D environment elements (buildings, etc ...). Additionally, if the audio emitter is blocked by one 3D Object, but bounced off of another before being received, the receiver needs to detect the angle (or line of direction) from which it is hearing the audio emitter.
Does anyone know how to do this, or have any idea on how to achieve it?
Thanks in advance!
Edit (5:25pm 5/26/2011)
How about using a (really large for long distances) a spherical collider that grows in size like a balloon until it "hits" the player. The player will be surrounded by 8? colliders in an effort to better determine which side the signal is hitting. However, this spherical collider idea doesn't take into account 3D objects and obstructions.
How important is it that it's accurate? Does sound need to travel at the speed of sound also? Or can it all be faked to make the player believe that's what's happening but in reality it's just some effects blended over the sound?
Speed of sound is not relevant. The concept behind it is the listener is a "listening device" that detects audio signals within a large 3D Environment (5 miles + .. point being, not a small room). Once the audio signal is detected, the listening device stores into memory (code stuff) the angle from which it was received in relation to itself and plots a line along those two points.
Answer by Muzz5 · May 26, 2011 at 08:40 PM
Here's the problem...Unity's audio stuff sucks. If you want better stuff, just send angry messages demanding write access to audio buffers, which would allow you full access to the power of FMOD! But, we don't have that, so for now you'll have to fake it. I'll write up a longer answer if you need it on faking it. One thing though, if you're using a 5 mile radius terrain, you might want to go into Project Settings-> Audio and change the speed of sound a bit, or you'll get a delay.
Thinking about it, it's quite hard to fake the sound bouncing. The problem is that sound isn't stopped - it pays no notice to objects. But I'm thinking, why not have another audio source close to the player/whatever? But with a volume/pitch which you change through script. And the closer you get to the 'real' place (where there is no source) the louder the source gets. That's what I'm thinking of, anyway.
Thanks $$anonymous$$uzz. I had a feeling that basic audio listeners won't suffice, and that I will end up having the need for some sort of ranged signal concept (which mimics the concept of an audio signal).
I am fully opened to all ideas for faking it. Sometimes faking a concept leads to the creation of a whole new better concept. Lay it on me .. :)
Answer by Scribe · May 26, 2011 at 09:02 PM
Just an idea and i don't really know how to implement this but do you actually need the Sound to bounce,
I was thinking you could use a load of ray casts possible to create all the bouncing effect and then if the ray cast eventually hits the player/receiver you play the sound file attached to the player
Just an idea and not sure how you would implement it but I'm not sure you can reflect sound as Muzz5 said it doesn't get effected by objects so this might be an alternative
hope its helpful
Scribe
Thanks Scribe. The audio file itself can reside on the player (it will be inaudible noise anyways). What I really need is for the player to "pick up" signals from a distance and record the angle / location at which it was received. By way of doing this over a few locations (by moving the player and thus the reception point), the player can focus in on the point of origin for the signal.
It's basically a sound emitting device off in the distant to which the player hears it, plots points and eventually locates the sound emitting beacon.
Ray casts would work I guess, b/c they return a lot of data, but is that a solid approach to "receiving" signals when the listener is mobile?
oh ok I didn't really understand your question obviously :P I'm still not sure if I fully understand but if it is useful and relevant I made a script for an fps game which changes the angle finds the angle at which a bullet hit you? it sounds like it could possibly help. If you need it tell me but I won't post it straight off as I would propbably spend ages trying to find it :)
Thanks Scribe. Any code you can provide, especially concerning angle math would be greatly appreciated. I have trouble with that stuff. Hope it doesn't take you all that long to locate ... I don't want you growing old in the process :)
haha I found it and I've made a new answer with it, not sure it will help you as it is to detect a physical collision and its a bit rough but it worked for the bullet hitting my character
You don't reflect sound in my example. You slightly change the pitch to give it an appearance of doing that. And 3D sounds will work for angle.
Answer by Scribe · May 27, 2011 at 10:01 AM
ok Im not sure if this will be at all useful for what you want but you could try something like this:
var targeter : Transform;
function OnCollisionEnter(other : Collision) {
print("First point that collided: " + other.contacts[0].point);
var collision = other.contacts[0].point;
targeter.LookAt(collision);
}
basically I have my person(capsule) and inside my capsule there is a small cube (targeter). my code gets the point that something collided with the capsule and makes the cube inside look at it. I had to do it like this because I didnt have anyidea of how to transform the Vector3 into an angle so I made the cube which is at the centre of my person look at it and I used the rotation of the cube to work out its angle in relation to my person.
It works but in a round about way
as I said I'm not sure it will be really any help as the sound isn't a physical collision but you might be able to work off and adapt this
Scribe
Thanks Scribe. I kind of had an idea where my player would have some sort of collider. I'm still in a data gathering phase before I start developing, but I'll give your code a test and I'll let you know the outcome when I do. Thanks for you help.
Answer by Sren Christiansen · Jun 06, 2011 at 02:40 PM
Hi Muzz5, Before you go all crazy about how Unity's audio suck, think about how you would implement reflection of audio with FMOD?. You will probably end up with some raycasting against occluding objects, some LPF, Reverbs, volume and pitch manipulation. All nicely exposed by Unity. Audio Buffer access (which is on the way) will give you one thing here, the ability to rewrite effects, mixing etc.. Building a reflection system from that will probably take some time.
cheers, søren
can the F$$anonymous$$OD broadcast audio / sounds across long distances and still be heard, as opposed to a local 3d Sound that fades as you move further away? I guess I could just test this myself, but thought I'd ask here anyways.
You can control the attenuation as you like with the volume curves.
Your answer
Follow this Question
Related Questions
There is no 'AudioSource' attached to the 4 Answers
How to play a sound when a prefab button that changes scene is clicked 3 Answers
Music Visualiser Troubles 0 Answers
Multiple audioSources on same gameObject? 1 Answer
Audio.Play() not showing up 1 Answer