Best way to create a sound loudness system for a zombie game?

I’m making a 28 Days Later inspired game, and for my zombie AI it has a function to wander if it has no target; I’m following a tutorial made by Y3llow Mustang on youtube (https://www.youtube.com/watch?v=ibvoqnG3YqI), and he has the AI wander to a goal variable calculating the humanoid root part’s position plus a random X and Z axis.

However, I want my zombies to move to a sound’s position if it’s playing (example, a gunshot from a player) and is in range between the sound’s position and its root part (if the max roll off is a bigger number than distance from sound to root part is best way i can describe it).

So I was thinking of creating a sound loudness system where every gunshot/footstep or whatever makes a certain level of sound.

unfortunately, i have no clue how I should do this and how to keep it organized, so if any of you could give me tips to keep things clean and how to approach this, i’d greatly appreciate it!

1 Like

You could do something like this if there isnt a current target (I made this on mobile, be sure to check any mistakes)

while task.wait() do
if target = nil then
for _, sound in pairs(workspace:GetDescendants()) do
if not sound:IsA("Sound") then continue end
local soundPart = sound:FindFirstAncestorOfClass("Part")
if sound.IsPlaying == false or soundPart == nil then continue end
local distance = (zombieRootPart.Position - soundPart.Position).Magnitude
if distance > then sound.MaxRollOfDistance then continue end --Checks if the sound is to far away for the zombie to hear it
target = soundPart
local targetPosition = soundPart.Position --The final position the zombie should walk toward to
end
end
end

ill try to implement this and see what hapens. thank you!

I think it would be easier to fake this system then to actually rely on real sounds.

For every action the player can make that makes sounds (walking, sneaking, jumping, shooting, etc) you decide how many studs you want that specific sound to reach.

For instance:

  • The player shoots their weapon.
  • You save the position of the player when the shot is fired.
  • You check if a zombie is within x amount of studs from the player that made the sound.
  • If in range you use pathfinding to make the zombie walk towards the origin of the sound.

You do this whenever a player does an action that makes sound.
When the player is walking you perhaps do a check every second.

This system does not take into account if a zombie in another room with thick walls etc. But this is a start.

1 Like

this also sounds really smart, i like this idea! i think i’m going to add the loudness system for zombies to detect when theyre wandering, but this is very helpful, thank you!

1 Like