Making enemies respond to sound

Hi there!

I am currently working on a project and were wondering, is it possible to make it when you fire a gun NPCs nearby will ‘hear’ it and run to the location the gunshots were at?

3 Likes

I’ve actually been working recently on a stealth game inspired by Thief (although I dropped it after the AI scripting just got too much to handle for me).
I found using playback loudness to detect the noise level to be fairly inaccurate, so instead I opted to just check whenever the player was moving, and if they were moving, run through a list of NPC’s to check their distance form the player.
If the NPC was below a set number in distance to the player, then they would be able to hear the player’s footsteps and thus move towards the position where they heard the noise.

I’m unsure how efficient this would be with a large number of NPC’s, but I found it to work perfectly fine for me.

3 Likes

This sounds pretty cool, I sure do hope that once you gained more experience you’ll consider giving that game a try again, Roblox really lacks stealth games.

Sadly though, this doesn’t really help me. I am not working on a stealth related game, it is a top down view shooter (Online & somewhat of a story mode). The game overall took a lot of inspiration from Hotline Miami, firing a gun here is more of a “well now you went loud and are screwed” thing. The game is meant to be played fast, not sneaking around.

I thank you for contributing though, I really appreciate your effort! :grinning_face_with_smiling_eyes:

1 Like

I mentioned my past project because the same general idea can still be applied to your game.
Whenever your gun is fired, you can go through a list of NPC’s in the level and check their distance from the player. If they are within range of the sound, move the NPC’s towards the player.

Or, if you like, you can skip the entire process of checking the NPC’s distance to the player, and just start moving them towards the player immediately after they fire a gun.

6 Likes