Audio Based Radar System Help?
I'm looking for a way to create a radar system similar to what's found in Metal Gear Solid Peace Walker. An inner circle shows the volume of the players sounds, which is visualized by an inner ring distorting the amount of volume the player produces. An outer circle shows the direction and volume of everything else.
How would such a radar system be achieved? I can imagine that it'd use line renderers or splines to create the circles, which would be split into points which would then be individually distorted according to volume. However, I'm getting hung up on the outer circle. How can I detect the direction from the audio listener on the player, and then apply that volume variance and direction to the radar in the correct orientation?
I guess for performance I could fake the actual waveforms and simply use some RNG for the distortion amount multiplied by the volumes. However, actually achieving the radar would be an important first step.
Thanks Sylux102
S$$anonymous$$lth games normaly simulate noise and hearing for the AI. They just look at what the character is doing, assign a "volume", that deter$$anonymous$$ds how far it's hearable and then message every listener in the surrounding about that noise and what caused it (AIs shouldnt have to guess based on what sinus wave they are getting). What you want is beyond Unitys default audiolistener and you would have to implement your own "awarness system". That does not mean, that you replace Unitys audio components, rather that use your system for deter$$anonymous$$ding what the AI hears and Unitys audio components to let the player hear your gamesounds.
Im not so much having an issue with what AIs are hearing. I'm looking for taking "surround output data" if you will from the audio listener component to apply it to a HUD element for the players radar. I've already achieved the inner circle, using the following hacked up code from a Reddit user.
AudioSource audioSource;
public LineRenderer waveform;
public float waveformHeight = 5f;
public float waveformRadius = 20f;
const float TWOPI = 6.283185f;
const int WAVEFOR$$anonymous$$_SA$$anonymous$$PLES = 1024;
const int FFT_SA$$anonymous$$PLES = 4096;
float[] fft = new float[FFT_SA$$anonymous$$PLES],
fft_history = new float[FFT_SA$$anonymous$$PLES],
data = new float[WAVEFOR$$anonymous$$_SA$$anonymous$$PLES],
data_history = new float[WAVEFOR$$anonymous$$_SA$$anonymous$$PLES];
void Start()
{
waveform.SetVertexCount(WAVEFOR$$anonymous$$_SA$$anonymous$$PLES);
}
void Update()
{
audioSource.GetSpectrumData(fft, 0, FFTWindow.BlackmanHarris);
audioSource.GetOutputData(data, 0);
Vector3 vec = Vector3.zero;
for(int i = 0; i < WAVEFOR$$anonymous$$_SA$$anonymous$$PLES; i++)
{
int n = i < WAVEFOR$$anonymous$$_SA$$anonymous$$PLES-1 ? i : 0;
vec.x = $$anonymous$$athf.Cos((float)n/WAVEFOR$$anonymous$$_SA$$anonymous$$PLES * TWOPI) * (waveformRadius + (((data[n] + data_history[n]) * .5f) * waveformHeight));
vec.z = $$anonymous$$athf.Sin((float)n/WAVEFOR$$anonymous$$_SA$$anonymous$$PLES * TWOPI) * (waveformRadius + (((data[n] + data_history[n]) * .5f) * waveformHeight));
vec.y = 0f;
waveform.SetPosition(i, vec);
}
I'm just having issues applying directional audio data using this method. The above cs is attached to a gameobj with a linerenderer component and audio source to test. Works exactly as I want. Just can't figure out directional audio for this.
Your answer
Follow this Question
Related Questions
What causes the audio clicking & how do I get a clean sound? 11 Answers
How can I turn off the sound from another scene? 0 Answers
how to make sound settings button? 1 Answer
Sound doesn't always play 0 Answers