Search Unity

Question Footsteps Audio - Material Change Overlapping Colliders Not Working

Discussion in 'Audio & Video' started by Alexapo, Apr 13, 2021.

  1. Alexapo

    Alexapo

    Joined:
    Apr 6, 2021
    Posts:
    10
    So I am trying to create Footsteps sounds in Unity with Wwise and change the sounds depending on what type of material the player is walking on.

    What I have done is create box colliders for the spesific material I want to make a different sound for and a default sound that plays when the player is not in this area. So, there is a default sound that plays a footsteps sounds, and when the player enters the box collider, the footstep sound changes, and when the player exits the colliders, the sound changes to the default sound. This is how the colliders look:

    View attachment 833593

    The way I have it set up works - ish. On each of the colliders I have this script:

    View attachment 833590
    I also have the colliders set to "Is Trigger".
    View attachment 833596

    What happens is that when the player exits one collider and enters an overlapping collider, the OnTriggerExit still triggers instead of the new OnTriggerEnter of the overlapping collider. I am not a programmer, so this might be an easy fix, but if anyone could help with this that would be great. The goal is to make sure that the OnTriggerExit only triggers as long as the player exits the collider completely and not enters an overlapping collider. The footsteps sound should be the same across all the colliders and only change back to the default sound when the player completely exits the colliders.

    If there for example is a way to check if the player is still inside a collider when the OnTriggerExit function is triggered that says that if the player is still inside a collider, do not change the sound or something like that.

    Any help would be appreciated!
     
    ravnur_376 likes this.
  2. JLF

    JLF

    Joined:
    Feb 25, 2013
    Posts:
    140
    Hi, I had this same issue before when trying to use multiple primitive colliders as one and the easiest way for me was to simply add up how many colliders you have entered or left to determine whether you're still in one.

    For example, every time you enter a collider, add one, every time you leave, subtract one. If the total value is one or more, you're inside a collider.

    I wrote about it on my blog, which includes an example, here: https://gamedevbeginner.com/10-unity-audio-tips-that-you-wont-find-in-the-tutorials/#audio_zones

    Hope that helps.