// Start is called before the first frame update
 void Start()
 {
     if (!perception)
     {
         perception = GetComponent <P2DSubject>();
     }
     perception.hearEvent.AddListener((P2DSound sound, float audioLevel) => {
         _lastSoundHeard = sound;
         _heardSound     = true;
     });
 }
    public static float GetAudioLevel(P2DSound sound, Vector2 ears)
    {
        float distance = (ears - sound.origin).magnitude;

        if (distance > sound.radius)
        {
            return(0f);
        }
        else
        {
            return(distance / sound.radius); // linear falloff for now
        }
    }
    private void PreStateUpdate()
    {
        // Check if player within auto-find distance
        if (!player.isHidden && Vector2.Distance(transform.position, player.transform.position) <= behaviourSettings.autoSeePlayerDistance)
        {
            _isSuspicious = true;
            _canSeePlayer = true;
            SetInvestigatePoint(player.transform.position);
            return;
        }

        // Else check if player visible
        if (player.visibility > 0f && fieldOfView.IsInFOV(player.transform.position))
        {
            Vector3 losPoint = Vector3.zero;
            if (!player.isHidden && HasLineOfSightToPlayer(out losPoint))
            {
                _isSuspicious = true;
                _canSeePlayer = true;
                SetInvestigatePoint(losPoint);
                return;
            }
        }

        // Else check if heard something
        if (_heardSound == true)
        {
            _isSuspicious = true;
            SetInvestigatePoint(_lastSoundHeard.origin);
            _lastSoundHeard = null;
            return;
        }

        _canSeePlayer = false;
        _isSuspicious = false;
    }
Exemple #4
0
 public void RegisterSound(P2DSound sound)
 {
     soundBuffer.Add(sound);
 }