Hasli4

Untitled

Sep 6th, 2026
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. local npc = script.Parent
  2. local humanoid = npc:WaitForChild("Humanoid")
  3. local root = npc:WaitForChild("HumanoidRootPart")
  4.  
  5. local corner = workspace:WaitForChild("corner")
  6. local finish = workspace:WaitForChild("finish")
  7.  
  8. -- Скорость рыцаря
  9. humanoid.WalkSpeed = 10
  10.  
  11. -- Расстояние, при котором считаем точку достигнутой
  12. local REACH_DISTANCE = 2
  13.  
  14. -- Поворачивает рыцаря лицом к нужной точке
  15. local function faceTarget(target)
  16. local direction = target.Position - root.Position
  17. direction = Vector3.new(direction.X, 0, direction.Z)
  18.  
  19. if direction.Magnitude > 0.01 then
  20. root.CFrame = CFrame.lookAt(
  21. root.Position,
  22. root.Position + direction
  23. )
  24. end
  25. end
  26.  
  27. -- Идти к точке
  28. local function walkTo(target)
  29. -- Сначала разворачиваемся в сторону точки
  30. faceTarget(target)
  31.  
  32. humanoid:MoveTo(target.Position)
  33.  
  34. -- Ждём, пока NPC дойдёт
  35. while true do
  36. local distance = (root.Position - target.Position).Magnitude
  37.  
  38. if distance <= REACH_DISTANCE then
  39. break
  40. end
  41.  
  42. -- Если NPC почему-то перестал двигаться,
  43. -- повторяем команду MoveTo
  44. humanoid:MoveTo(target.Position)
  45.  
  46. task.wait(0.2)
  47. end
  48.  
  49. -- Полностью останавливаемся
  50. humanoid:MoveTo(root.Position)
  51. end
  52.  
  53. -- Бесконечный патруль
  54. while true do
  55. -- corner -> finish
  56. walkTo(finish)
  57.  
  58. -- Небольшая пауза
  59. task.wait(0.5)
  60.  
  61. -- Разворот и движение обратно
  62. walkTo(corner)
  63.  
  64. -- Небольшая пауза
  65. task.wait(0.5)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment