basically im trying to make the minecraft warden, and the warden is blind and cannot see so it relies on sound to find its prey.
how would i make something that can listen for sounds?
basically im trying to make the minecraft warden, and the warden is blind and cannot see so it relies on sound to find its prey.
how would i make something that can listen for sounds?
I’m very confused on what you mean. Do you mean that the walk noise will lure the warden? Or is there another way to make noise in your game?
yeah i want to make it so it can listen for sounds and the warden will go after it
example, if player makes a sound and the warden is within range to be able to hear it, it’ll start running towards the player
here’s the wiki page about it
Ok, I know what the Minecraft Warden is, I’ve played Minecraft. But are you saying that EVERY single noise a player makes the warden will go after? If so, this is pretty diffucult
not like every sound, but when they are sneaking no, but running yes
just sounds that are loud enough, that the warden will detect
you could check humanoidrootpart assemblylinearvelocity, thats how i used to do it, (and no, i dont have the code anymore, sorry)
or, simply, use remote events whenever the players walk sound is played
You could probably create a sound in workspace under a BasePart and check for the distance between the BasePart and enemy:
Example
-- Enemy script
local collectionService = game:GetService("CollectionService") -- CollectioService is useful for groups of objects
local soundTag = "Noise" -- The CollectionService tag of the parts that are created
local function getDistance(basepart: BasePart) : number
-- Returns the distance (in studs) between the enemy and the sound
-- 'EnemyPos' would be the position of the enemy
return (EnemyPos.Position - basepart.Position).Magnitude
end
local function onItemAdded(instance: BasePart)
local distance = getDistance(instance) -- Get the distance
local sound = instance:FindFirstChildOfClass("Sound") -- Get the sound Instance
-- The sound instance can be useful for seeing how loud the sound is via
-- the Sound.PlaybackLoudness property
if (distance < 12) then
-- this checks if the distance is less than a certain amount of studs
--... do something
end
end
-- Detect when a new sound is created
collectionService:GetInstanceAddedSignal(soundTag):Connect(onItemAdded)
-- Sound Creation
local collectionService = game:GetService("CollectionService")
local soundTag = "Noise"
local function createSound()
local part = Instance.new("Part")
local sound = Instance.new("Sound")
part.CFrame = -- CFrame of where the sound will be created
part.Anchored = true -- Make the object anchored
part.Transparency = 1 -- Make the object invisible
part.CanCollide = false -- Disable collisions
part.Parent = workspace -- Parent the object to workspace
sound.SoundId = "rbxassetid://" -- SoundId of the sound
sound.Parent = part -- Parent the sound to the object
sound:Play() -- Play the sound
collectionService:AddTag(part, soundTag) -- Add the "Noise" tag to the object
end
createSound() -- Creates a new sound
This is just how I would go about making a system like this.
This is a little late, but here’s the scripts in a practical sense (distance set to 40 studs):
Whenever a sound is created, the NPC hears it and moves towards it
what about projectiles, samething?
Well I guess what you could do is if the player is sprinting then you could create an invisible part that the warden moves to
Example:
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input == Enum.KeyCode.Shift then
player.Character.Humanoid.SpeedAmount = 50 -- or whichever number you want
local headPos = player.Character:WaitForChild("Head").CFrame
local headBrick = Instance.new("Part")
headBrick.CFrame = headPos
local warden = --wherever your warden is located
warden.PrimaryPart.CFrame = headBrick.CFrame
--if you have an animation to move your warden you will need to change the line above
end
end)
You could say, for every time you run a play function in your script( Example: Run:Play() ).
Check if the distance from the warden to the player is in a specific range, if so then let the warden walk to the player.