I’ve made an npc that wanders around the house, the only problem is he constantly is at walls directly staring at them 24/7, is there a way I can make the npc detect the wall and then redirect from it?
You could use raycasting. Though the issue lies in your script. Can you paste the script so I can help you?
(Sorry im not sure how to post code correctly so its scattered out)
local CurrentPart = nil
local MaxInc = 30
function onTouched(hit)
if hit.Parent == nil then
return
end
local humanoid = hit.Parent:findFirstChild("Humanoid")
if humanoid == nil then
CurrentPart = hit
end
end
function waitForChild(parent, childName)
local child = parent:findFirstChild(childName)
if child then
return child
end
while true do
print(childName)
child = parent.ChildAdded:wait()
if child.Name==childName then
return child
end
end
end
local Figure = script.Parent
local Humanoid = waitForChild(Figure, “Humanoid”)
local Torso = waitForChild(Figure, “HumanoidRootPart”)
local Left = waitForChild(Figure, “LeftFoot”)
local Right = waitForChild(Figure, “RightFoot”)
Humanoid.Jump = true
Left.Touched:connect(onTouched)
Right.Touched:connect(onTouched)
while true do
wait(math.random(2, 6))
if CurrentPart ~= nil then
if math.random(5, 7) == 1 then
Humanoid.Jump = true
end
Humanoid:MoveTo(Torso.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc)), CurrentPart)
end
end
Got this code from here: Making random movement AI? - #7 by NinjoOnline
local character = script.Parent
local humanoidRootPart = character:WaitForChild('HumanoidRootPart')
local humanoid = character:WaitForChild('Humanoid')
local base = workspace.Base
character.Humanoid.WalkSpeed = 100
local walkTime = math.random(3, 5)
local waitTime = math.random(1, 3)
while true do
humanoid:MoveTo((base.CFrame * CFrame.new(math.random(-base.Size.x / 2,base.Size.x / 2), humanoid.HipHeight, math.random(-base.Size.z / 2,base.Size.z / 2)).Position))
humanoid.MoveToFinished:Wait()
end
Select a random base each time (base is the floor of the house) and you got yourself a working NPC.