Search Unity

Detecting Proximity of audio playing in area to an object?

Discussion in 'Scripting' started by khos85, Jun 20, 2016.

  1. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Hi,

    I would like to ask if anyone has ideas on the following that they could suggest:
    Detection of Proximity of audio playing in area to an object? I want to be able to scare a bird object away if a player object gets to close but detect this by amount of the sound of the object makes, if the audio is too loud then the bird object will move away.. but I am not sure how to approach this, e.g. is there a collider style class for audio sources?

    Thanks for any ideas or guidance anyone s able to offer.
     
  2. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Actually, I think I might try a different approach to this, using a distance to transform calculator..
     
  3. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Speed wise.. use (target - current).sqrMagnitude < distance * distance;

    The sqrt in Distance/Magnitude is something you want to avoid overusing.
     
  4. khos85

    khos85

    Joined:
    Jul 21, 2013
    Posts:
    541
    Thanks for your reply, much appreciated. I was able to get what I wanted by calculating the distance between objects and used that.