CanHearObject can't hear player

CaptCanada

New member
Hi all

Just wondering if I need to have anything else active in the task in order for my agent to hear the player.

I have the Target Object set to a custom FPS controller, namely the controller from the TW Horror FPS Kit. I have

I need some explanation for the Hearing Radius and Audibility Threshold. I have both set to 50. What units do these use?

What source does the task look for in order to show success?

Thanks
 

volak

New member
I was having issues with the hearing task - are you sure your character is making noise?

My issues are specifically related to the lack of footstep noises on my terrain, hoping to get that fixed tonight. Might be your issue as well?
 

volak

New member
Ok I got Can Hear Object working for me - but TBH it took a bit of script changing im not confident about. To be sure though the task is not... working.
I hesitate to say its broken because I could be just using it incorrectly - but if you want to use it for listening for a specific game object tag - you have to change the task to this:

C#:
        // Returns success if an object was found otherwise failure
        public override TaskStatus OnUpdate()
        {
            GameObject found = null;
            if (targetObjects.Value != null && targetObjects.Value.Count > 0) { // If there are objects in the group list then search for the object within that list
                GameObject objectFound = null;
                for (int i = 0; i < targetObjects.Value.Count; ++i) {
                    float audibility = 0;
                    GameObject obj;
                    if (Vector3.Distance(targetObjects.Value[i].transform.position, transform.position) < hearingRadius.Value) {
                        if ((obj = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, targetObjects.Value[i], ref audibility)) != null) {
                            objectFound = obj;
                        }
                    }
                }
                found = objectFound;
            }
            else if (!string.IsNullOrEmpty(targetTag.Value))
            {
                var target = GameObject.FindGameObjectWithTag(targetTag.Value);
                if (Vector3.Distance(target.transform.position, transform.position) < hearingRadius.Value)
                {
                    found = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, target);
                }
            }
            else { // If the target object is null then determine if there are any objects within hearing range based on the layer mask
                if (usePhysics2D) {
                    if (overlap2DColliders == null) {
                        overlap2DColliders = new Collider2D[maxCollisionCount];
                    }
                    found = MovementUtility.WithinHearingRange2D(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, overlap2DColliders, objectLayerMask);
                } else {
                    if (overlapColliders == null) {
                        overlapColliders = new Collider[maxCollisionCount];
                    }
                    found = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, overlapColliders, objectLayerMask);
                }
            }

            if (found != null) {
                returnedObject.Value = found;
                // returnedObject success if an object was heard
                return TaskStatus.Success;
            }
            // An object is not within heard so return failure
            return TaskStatus.Failure;
        }
There were 2 bugs in both those functions which I fixed for my specific case but Im not confident it will work for anyone else so if it may be a good idea to just not use this task
 
Last edited:

CaptCanada

New member
Thanks Justin. My issue is that the agent doesn't seem to hear the gameobject, which is the fpscontroller. I have set the radius and level to various values and the agent doesn't seem to hear the player.

I can get right up behind the agent and there is no change in the behavior. I am using a non Unity fps controller, namely a fpscontroller from another asset, but the controller has a audio source on it, so I am not sure why the agent isn't picking this up, as I assume it's this that the agent is "listening" for?

It would be nice if you could select a specific sound object the agent is to listen for, say foodsteps or gunfire. Maybe I am not using the task properly?

Thanks in advance.
 
Top