I need to make a more advanced AI, but I don't know how to go about a few things. I want an AI to be attracted to certain positions based on noise-making, such as a bottle being thrown or a gunshot. But I don't know what to do in this case. Would I have the script create a set of values in the workspace that, if say the sound was made close enough to the ai and the ai isn't already focused on something, would cause the ai to wander around that position?
That's a simple way to do it.
If you simply keep track of all of the "sounds" made in the last few seconds, the zombies can track to those instead of the nearest player. If there are no nearby positions to take, just remember the old value, so that it'll keep tracking there (and you can add additional logic to make it wander).
Overall, it could look like this:
function makeNoise(position) local p = Instance.new("Vector3Value",workspace.Noises); p.Value = position; delay(function() p:Destroy(); end,10); -- Destroy the noise after ten seconds -- (since zombies might not look every moment, we give them -- a chance to notice) end function findNoise(near,within) local nearest = nil; for i,v in pairs(workspace.Noises:GetChildren()) do if (not nearest) or (nearest - near).magnitude > (nearest - v.Value).magnitude then nearest = v.Value; end end return nearest; end local target = myposition; local vary = Vector3.new(); while true do wait(); -- Other logic local noise = findNoise(myposition); if noise then target = noise; end if math.random() < .01 then vary = Vector3.new(math.random()*50-25,0,math.random()*50-25); --simple wandering end wandertarget = target + vary; moveTo(wandertarget); end