Hi there, I am trying to make a game similar to this Doom Mod, Creepy Doom WADs - do_not_play.wad - YouTube where you’re in a maze running away from the monster. The monster makes a noise which repeats faster and faster the closer you are to it, which I am trying to replicate.
The issue is, is that I’ve tried using lerp to change the threshold based of magnitude between two values, but that does not work as the change is rather in reverse (the closer you are, the slower the sound repeats).
I’ve attached my attempt below:
local function lerp(a,b,t)
return a+(b-a)*t
end
local sound = script.Parent["boom sound"]
local pitch = sound.pitch
local nextbot = script.Parent.Parent
local threshold = sound.TimeLength
game.Players.PlayerAdded:Connect(function(plr)
local connection : thread
plr.CharacterAdded:Connect(function(char)
sound.Volume = 10
if connection then
task.cancel(connection)
end
connection = task.spawn(function()
while true do
sound:Play()
print(threshold)
task.wait(threshold)
end
end)
game:GetService('RunService').Stepped:Connect(function()
local hrp : Part = char.HumanoidRootPart
local distance = (hrp.Position - nextbot.HumanoidRootPart.Position).Magnitude
threshold = lerp(sound.TimeLength,0.5,distance/10000)
print(distance/10000)
end)
end)
end)