I’m trying to make a game working with the idea of echolocation. We are connecting a mic to Unity and sounds will enable the flashlight to turn on and off. The volume and duration of the sound will determine the intensity and range of the light. We’ve created a black environment with white outlines so that even when the light shines on it all you can really see are the edges of our objects and environments. So far so good.
The issue we seem to be running into is that even with a black terrain, a black skybox and no other light sources, the outlines can still be seen even when the light is turned off. We’ve tried completely turning down the ambient light and jacking up the intensity of our spotlight, but when we do that nothing can be seen whatsoever, even with the spotlight.
Are we just missing something, or is there something special we need to do to solve this issue?
My programmer also just mentioned he’s having issues with the script he’s using. The script is having difficulty getting access to the variable of the light.
If anyone has any answers for that as well it’d be much appreciated!
using UnityEngine;
using System.Collections;
public class Audio : MonoBehaviour
{
Light l;//Need to determine how this will be accessed
GameObject o;
int qSamples = 256;
float refValue = 0.1F;
float rmsValue;
float dbValue;
float pitchValue;
private float[] sample; // audio samples
private float[] spectrum; // audio spectrum
void Start ()
{
// o = //UnityEngine.GameObject.FindGameObjectWithTag("First //Person Controller");
l = (Light)(o.GetComponent("Light"));
audio.clip = Microphone.Start("Built-in Microphone", true, 1,44100);
audio.Play();
sample = new float[qSamples];
spectrum = new float[qSamples];
}
void Update ()
{
if (audio.isPlaying)
{}
else if (audio.clip.isReadyToPlay)
{
audio.Play();
l.enabled = true;
}
else
{
audio.clip = Microphone.Start ("Built-in Microphone", true, 10,44100);
}
//FIGURE OUT ALGORITHM FOR AMOUNT OF LIGHT AND RANGE
//float y = audio.GetSpectrumData(128,0,FFTWindow.BlackmanHarris)[64]*1000000;
AnalyzeSound();
if (dbValue < 5)
{
l.enabled = false;
}
else if (dbValue < 30)
{
l.range = 9;
}
else if (dbValue < 60)
{
l.range = 30;
}
else if (dbValue < 100)
{
l.range = 80;
}
}
void AnalyzeSound()
{
audio.GetOutputData(sample, 0); // fill array with samples
int i;
float sum = 0;
for (i=0; i < qSamples; i++)
{
sum += sample_*sample*; // sum squared samples*_
* }*
* rmsValue = Mathf.Sqrt(sum/qSamples); // rms = square root of average*
_ dbValue = 20Mathf.Log10(rmsValue/refValue); // calculate dB_
_ if (dbValue < -160) dbValue = -160; // clamp it to -160dB min*_
* }*
}
The script is attached to a First Person Controller and the Spot Light is attached to the First Person Controller too. There is a diffuse shader being used.