Hi, I’m new to programming and currently trying to write up a simple audio visualiser where I just grab some spectrum data and scale the cubes with that. The problem is while it’s doing this it’s very jittery and I want it to scale smoothly. I’ve been looking around and found Lerp but I’m not sure how to use it with my code could someone point me in the right direction?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class audioSpecDazzle : MonoBehaviour {
public GameObject cube01;
public GameObject cube02;
public GameObject cube03;
public GameObject cube04;
public GameObject cube05;
public GameObject cube06;
public GameObject cube07;
public GameObject cube08;
public GameObject cube09;
public GameObject cube10;
public Vector3 initialPosition;
public float juice = 150f;
public float[] spec;
public float specMag01;
public float specMag02;
public float specMag03;
public float specMag04;
public float specMag05;
public float specMag06;
public float specMag07;
public float specMag08;
public float specMag09;
public float specMag10;
// Use this for initialization
void Start ()
{
Application.targetFrameRate = 999;
}
// Update is called once per frame
void Update ()
{
spec = AudioListener.GetSpectrumData(1024,0,FFTWindow.BlackmanHarris); // this works on audio source
//spec = AudioListener.GetOutputData (64,0); // this gives much better values.
specMag01 = spec[2] + spec[4] + spec[8];
specMag02 = spec [12] + spec [16] + spec [24];
specMag03 = spec[32] + spec[36] + spec[40];
specMag04 = spec[44] + spec[48] + spec[50];
specMag05 = spec[52] + spec[54] + spec[56];
specMag06 = spec[58] + spec[60] + spec[62];
specMag07 = spec[70] + spec[72];
specMag08 = spec [74] + spec [76];
specMag09 = spec [78] + spec [80];
specMag10 = spec [82] + spec [84];
cube01.gameObject.transform.localScale = new Vector3(1f,specMag01*juice,1f);
cube02.gameObject.transform.localScale = new Vector3(1f,specMag02*juice,1f);
cube03.gameObject.transform.localScale = new Vector3(1f,specMag03*juice,1f);
cube04.gameObject.transform.localScale = new Vector3(1f,specMag04*juice,1f);
cube05.gameObject.transform.localScale = new Vector3(1f,specMag05*juice,1f);
cube06.gameObject.transform.localScale = new Vector3(1f,specMag06*juice,1f);
cube07.gameObject.transform.localScale = new Vector3(1f,specMag07*juice,1f);
cube08.gameObject.transform.localScale = new Vector3(1f,specMag08*juice,1f);
cube09.gameObject.transform.localScale = new Vector3(1f,specMag09*juice,1f);
cube10.gameObject.transform.localScale = new Vector3(1f,specMag10*juice,1f);
}
}