How to make AI react to sounds?

Scripting questions, discussions, etc
5 posts Page 1 of 1
Posts: 914
Joined: Sun Feb 08, 2015 1:51 am
by Duion » Mon Feb 05, 2018 9:39 pm
I want to do that my AI bots can hear sounds and eventually react to it. For example you walk near a bot, he does not see you, but he can hear your footsteps and then eventually go to the source of the footsteps until he sees you, or same if he hears a shot.

What would be the best approach? In chat Jeff suggested a good way would be to keep all the AI players in an array list and every time a sound is played it checks if any of the AI players is in range and if so, have an extra function that eventually makes them react to it.

Has anyone done something like this yet?
Posts: 51
Joined: Thu Aug 13, 2015 5:58 pm
by LoLJester » Tue Feb 06, 2018 9:57 pm
Animation triggers. You can assign triggers in the ShapeEditor. When the animation hits that trigger, a call to script is made. There you can decide whether you want that sound to be heard or not. There is a resource on GG's website that expands on this feature.
Posts: 914
Joined: Sun Feb 08, 2015 1:51 am
by Duion » Tue Feb 06, 2018 10:10 pm
I'm talking about sounds, not animations. Animation triggers are for footstep decals, particles and sounds and it has nothing to do with AI players.
Posts: 17
Joined: Tue Feb 10, 2015 5:01 pm
by Caleb » Wed Feb 07, 2018 5:20 pm
LOLJester's idea is solid. Animation triggers are hooks to call code/script at specific times during the animation. As you pointed out it's already set up to handle footprints, sounds, and particles, but there's no reason that your own custom triggers can't call other scripts. Such a function call might resemble iterating through your AI, checking the distance from the bot to the sound source, ray casting, and deciding how your bot will behave after that.
Posts: 914
Joined: Sun Feb 08, 2015 1:51 am
by Duion » Wed Feb 07, 2018 7:49 pm
Not every sound is an animation, thats just the case for footsteps, a gun fire is not an animation, well it can be, but does not have to be. Other sounds are pickup items, throw items like interaction sounds, or if something explodes.
You can probably bind a large part of sounds to animations, but I don't think it is a good solution to always need an animation to trigger a sound which then triggers something else, it should be within the sound itself.

Another problem especially regarding footsteps is, that since the footsteps are animation triggered you can use an exploit to be able to run without causing footsteps and this is through skidding, this works that way, that you press walk and look where the animation plays and then you only slightly press the walk key so that the animation only plays for a little bit every time without ever hitting the animation point.
Well you can avoid this mostly by placing the footstep at the first frame, but this will lead to cause the footstep sound to happen far too often and will cause funny looking skidmarks from the footprint decals created if you just press the forward key a lot and not hold it pressed and of course the footprints will not match the animation where the foot really hits the ground.

It may work for a quick and dirty solution if it only affects some form of sounds like footsteps, but thats not really what I want. Also footsteps happen quite often, like 2 times per second and more and I don't know how good for performance it is to check for every player on every footsotep if any other player is in range and then do something, it should be more like a on/off thing, like causing footsteps = 1 which is set to 0 when the player stops or sneaks or whatever.
5 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests