Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local npc = script.Parent
- local humanoid = npc:WaitForChild("Humanoid")
- local root = npc:WaitForChild("HumanoidRootPart")
- -- Точки патруля
- local pathFolder = workspace:WaitForChild("NPCPath")
- local corner = pathFolder:WaitForChild("Corner")
- local finish = workspace:WaitForChild("finish")
- -- Настройки
- humanoid.WalkSpeed = 10
- humanoid.AutoRotate = true
- -- Чтобы NPC полностью управлялся сервером
- root:SetNetworkOwner(nil)
- -- Расстояние, на котором точка считается достигнутой
- local REACH_DISTANCE = 3
- -- Движение к точке
- local function moveToPoint(target)
- while true do
- local distance = (root.Position - target.Position).Magnitude
- -- Дошёл
- if distance <= REACH_DISTANCE then
- return
- end
- -- Отправляем NPC к точке
- humanoid:MoveTo(target.Position)
- task.wait(0.2)
- end
- end
- -- Бесконечный патруль
- while true do
- -- Corner -> finish
- moveToPoint(finish)
- -- Небольшая пауза
- task.wait(0.5)
- -- Разворот будет сделан автоматически Humanoid
- -- finish -> Corner
- moveToPoint(corner)
- -- Небольшая пауза
- task.wait(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment