Search Unity

Audio Occlusion, Obstruction and Eventually Propagation using Wwise

Discussion in 'Scripting' started by Audiobeast, Feb 16, 2018.

  1. Audiobeast

    Audiobeast

    Joined:
    Apr 23, 2014
    Posts:
    1
    Hello all,

    I was wondering if someone could help with my Unity Script. So basically I am using unity to call RTPC in Wwise that will set an LPF and other values. My end goal is to have something like Remedy's audio system in Quantum Break. Here is the link. Propagation is the end goal but for now what I want to accomplish is 3x3 ray casting from the player to sound sources that are defined by layerMask. The 9 ray casts will individually send data to Wwise. For example if 1 out of 9 rays are blocked, value of 10 will be sent to Wwise, if 2 out of 9 are blocked then a value of 20 ..etc.

    As of right now I was given some code to work with by someone on the Wwise forums but instead of the casts originating from the source I would like them to originate from the player.

    Here is my current script.
    P.S. Go easy on me, I am new to scripting and I mainly use Wwise for everything. I want to learn more under the hood. Any help is appreciated.

    Thank you!

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Propagation : MonoBehaviour
    7. {
    8.  
    9.     public Transform target;
    10.     public GameObject listener;
    11.  
    12.     // Use this for initialization
    13.     void Start()
    14.     {
    15.  
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.  
    22.         RaycastHit HitInfo1;
    23.         RaycastHit HitInfo2;
    24.         RaycastHit HitInfo3;
    25.         RaycastHit HitInfo4;
    26.         RaycastHit HitInfo5;
    27.         RaycastHit HitInfo6;
    28.         RaycastHit HitInfo7;
    29.         RaycastHit HitInfo8;
    30.         RaycastHit HitInfo9;
    31.         float playerDistance;
    32.  
    33.         Vector3 raycastDir = target.position - transform.position;
    34.         playerDistance = Vector3.Distance(target.position, transform.position);
    35.  
    36.         //Vector3 transform.
    37.  
    38.         Physics.Raycast(transform.position, raycastDir, out HitInfo1, playerDistance);
    39.  
    40.         if (HitInfo1.collider == null)
    41.         {
    42.             AkSoundEngine.SetRTPCValue("OcclusionObstructionRTPC", 0f, gameObject);
    43.             Debug.DrawRay(transform.position, raycastDir, Color.green);
    44.         }
    45.  
    46.         else if (HitInfo1.collider.tag == "LightWall")
    47.         {
    48.             AkSoundEngine.SetRTPCValue("OcclusionObstructionRTPC", 40f, gameObject);
    49.             Debug.DrawRay(transform.position, raycastDir, Color.red);
    50.         }
    51.  
    52.         else if (HitInfo1.collider.tag == "MedWall")
    53.         {
    54.             AkSoundEngine.SetRTPCValue("OcclusionObstructionRTPC", 45f, gameObject);
    55.             Debug.DrawRay(transform.position, raycastDir, Color.red);
    56.         }
    57.  
    58.         else if (HitInfo1.collider.tag == "HeavyWall")
    59.         {
    60.             AkSoundEngine.SetRTPCValue("OcclusionObstructionRTPC", 55f, gameObject);
    61.             Debug.DrawRay(transform.position, raycastDir, Color.red);
    62.         }
    63.  
    64.         else if (HitInfo1.collider.tag == "Obstruction")
    65.         {
    66.             AkSoundEngine.SetRTPCValue("OcclusionObstructionRTPC", 70f, gameObject);
    67.             Debug.DrawRay(transform.position, raycastDir, Color.red);
    68.         }
    69.     }
    70. }
    71.  
    72.