Beispiel #1
0
 void Awake()
 {
     //Physics.autoSimulation = false;
     timerUtils              = new TimerUtils(BPMUtils.GetDuration(BPM, 64)); //change scene every 64 beats at 140 BPM
     initMe                  = true;
     Keyboard.reset         += Reset;
     Keyboard.changeShape   += UpdateShape;
     Keyboard.changeQuality += UpdateQuality;
 }
    void Update()
    {
        //change camera rotation direction
        if (timerUtils.ReadyToUpdate())
        {
            NewDirection();
        }

        //camera wobble
        Vector3 bounceDirection = transform.position.normalized;
        float   rms             = audioPlayer.GetRms();
        float   at32            = Time.time % BPMUtils.GetDuration(BPM, 32);
        float   wobble          = Mathf.Sin(at32 * 28) * rms * 0.4f;

        wobble += Mathf.Sin(at32 * 28) * 0.5f *  //frequency and amplitude
                  Mathf.Max(1 - at32 * 0.5f, 0); //decay

        Vector3 targetPosition = transform.position.normalized * 22.0f;

        transform.position = Vector3.Lerp(transform.position, targetPosition, 0.03f);         //prevent camera drifting
        transform.Translate(bounceDirection * wobble);
        transform.RotateAround(Vector3.zero, targetDirection, 20 * Time.deltaTime);
        transform.LookAt(Vector3.zero);
    }
 void Start()
 {
     timerUtils  = new TimerUtils(BPMUtils.GetDuration(BPM, 8));
     audioPlayer = FindObjectOfType <AudioPlayer>();
 }