Third Person Controller Footstep system and Behavior Designer Can Hear Object Task

DragonFist

New member
1. Character Controller Type (Ultimate Character Controller, First Person Controller, etc).

Third Person Controller (though I suspect it applies to any of them.) and Behavior Designer

2. Unity Version (beta Unity versions aren't supported)

Unity 2018.2.16f1

3. Bug Description

Can Hear Object Task from Behavior Designer is not working well with the footstep system. I discovered this in my own scenes, but it can be reproduced in the Behavior Designer integration demo scenes .I've opened the thirdpersonmelee scene and it does not seem to work there either. I can walk behind agent nolan all night and they never hear me.

4. Steps to Reproduce

The layer mask doesn't seem right to me (as the characters are on the character and subcharacter layers not the enemy layer), but I've tried changing it to character and subcharacter to no avail. I tried changing the footstep type to set interval and it started getting heard by the task. Not sure why that would be different. However, the default bodystep type and other types don't every trigger the Can Hear Object task. The body step, doesn't seem to trigger it even though I can hear the steps in the audio.

Anyhow, the ThirdPersonMelee demo scene has the same behavior for me out of the box (other than building the nav mesh). Just bake the nav mesh and walk behind agent nolan and without being seen and have watch the behavior tree. Agent Nolan never reacts in game and Can Hear fails in the tree. Changing the player's footstep type to interval and fixing the layers on the Can Hear task to include the character and subcharacter layers can get it working but changing the layers only doesn't help with the body step footstep type.



5. The full error message (if any)

No error messages
 
This is related to line 199 of MovementUtility. When Can Hear Object checks for AudioSources it does a GetComponentsForType which only checks the main object for AudioSources. If you change that line to:

Code:
if ((colliderAudioSource = targetObject.GetComponentsInChildren<AudioSource>(targetObject)) != null) {
Then it'll check for all of the children audio sources as well. This isn't as performance friendly though so I need to think of a better way to handle this case.
 
Hi @Justin,

Just wondering if this has been fixed?

I'm having what seems like the same issue that others have had, in that the enemy agent can't hear any audio from the player. I've tried multiple settings for radius and threshold but nothing seems to work.

Cheers
 
Last edited:
Thanks @Justin,

I just gave it a try and assigned all our UFPS (The player) audio objects to a game object list and it still looks like nothing is happening. I have a radius of 50 which visually looks good, and a threshold of 10 . I've also tried assigning the player tag to the Target Tag field

Are there any recommended settings or another method I might try?
 
Last edited:
The best way to debug this is to place a breakpoint within CanHearObject.OnUpdate and see where the task is failing when you think that it should be returning success. There are a lot of factors that go into determining if audio can be heard so placing a breakpoint is the best method to debug.
 
Hi @AmazingPunk and @DragonFist.

I had this same issue when using the demo third person scene. It took a bit of testing and going through the code to figure out what the issue was and to fix it for me. You probably figured out the answer by now, but hopefully, this helps someone else out in the future.
  1. The first thing is to apply the work around @Justin mentioned above in the comments, so that audiosources in the children are checked as well.
  2. In the demo scene, the Third person controller when shooting the assault rifle does not have a sound clip assigned for shooting. There is only a sound when the bullet hits another object like the grass, AI character, etc. So add in an audio clip under Nolan>>Items>>AssaultRifle>>Use>>AnimatorAudio>>AudioClips.
  3. Open the behavior designer and select Agent Nolan. Then go to Can Hear Object and select the inspector.
  4. Use the target object or target objects options...not the object layer mask and max collision count. (Probably can make the object layer mask and max collison count options work as well, but it seemed harder to get it work.) Under target option drag in Nolan (Not the AI Agent Nolan).
  5. Adjust the hearing radius so it is large enough that the player is making noise inside the hearing radius for the AI to hear. Use the gizmos in the scene view to see the hearing radius.
  6. Finally, put Audibility Threshold to 0.
Now the AI player should hear the player and chase them anytime the player walks or fires their weapon inside the hearing radius.

The issue that I found that was happening is that there is a check in the MovementUtility script to see if audibility > audibilityThreshold. In the code just above that check the audibility is calculated. The audibility almost always comes out to be a number very close to zero, for example 0.0015. So Audibility Threshold needs to be basically 0 or a very low number like the example in order for the AI to hear the sound and chase the targetObject in the demo scene.
 
@Maximuz24 Did you try Item#2. My guess is you don't have the sound clip assigned for shooting. There is probably only a sound playing when a bullet hits another object like the grass. You need to add the audio clips.
 
@Maximuz24 does the AI hear you when you move around in the level from the noise your footsteps make? If not, then I would recheck those steps. If the AI can hear the player then it is probably because of number 4. Maybe the sound being played from the gun is not on Nolan. The AI is only searching for sounds from the list. So if the gun sound is being played somewhere else then add in that game object to the list.
 
@KO_Games When i move around AI can hear me and seek me but when i fire ai cant hear that .I have added sound on player >items >pistol.Which list u mean to say.
Many Thanks
 
@Maximuz24 On the behaviour designer under the Can Hear Object. Select the inspector. One of the options is choosing which gameobjects the AI is listening for. Maybe try dragging in the pistol gameobject in there as well. See if that works.
 
@Maximuz24 If you add a game object to listen to you need to assign one of the feet of your character as this is where the footstep sound is emitted.

I ended up making a global variable for this and assign it at runtime.
 
Hey just posting this in case anyone needs it, In order for the agent to hear your weapon sounds, you also need to add your camera component to the targets list as well as Nolan.
 
Top