Can Hear Object sensitivity bug

SXtheOne

New member
Hi,

I suspect there is a bug related to the Can Hear Object task.
Here a snippet from the WithinHearingRange method (MovementUtility.cs):

if (colliderAudioSource.rolloffMode == AudioRolloffMode.Logarithmic) {
audibility = 1 / (1 + colliderAudioSource.maxDistance * (distance - 1));
} else { // linear
audibility = colliderAudioSource.volume * Mathf.Clamp01((distance - colliderAudioSource.minDistance) / (colliderAudioSource.maxDistance - colliderAudioSource.minDistance));
}
if (audibility > audibilityThreshold) {
return targetObject;
}


Let's say we set the player foot sound:
- max distance to 0.5
- min distance 0
- Volume Rolloff is linear
The AI's distance is 22 units from the player and the audibility receives 1 instead of 0 because Math.Clamp01((22 - 0) / (0.5 - 0))

I think the problem can be something like this for the linear rolloff:
if (distance >= colliderAudioSource.maxDistance)
{
audibility = 0;
}
else
{
if (colliderAudioSource.rolloffMode == AudioRolloffMode.Logarithmic) {
audibility = 1 / (1 + colliderAudioSource.maxDistance * (distance - 1));
} else { // linear
audibility = colliderAudioSource.volume * (1 - Mathf.Clamp01((distance - colliderAudioSource.minDistance) / (colliderAudioSource.maxDistance - colliderAudioSource.minDistance)));
}
}

So it's wrapped in an if-else and there is a fix for the linear rolloff as well.

I haven't checked the logaritmic rolloff code, I hope you'll check that as well. Also I haven't tested my solution for .minDistance so that may have side effects.

What do you think?

Note: it looks like parts of the code disappears randomly when I post. For example all the [ i ] diappeared from colliderSource and it makes harder to post.
 
Last edited:
I haven't had a chance to do the tests that I want to perform but since you have a working solution I'd go with that for now. I'll let you know as soon as I have time to properly test.
 
Just giving you a heads up that I looked into this and your changes look good :)
 
Top