kyo_kyo

Untitled

Dec 22nd, 2024
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. local animcontroller = script.Parent:FindFirstChildOfClass("AnimationController"):WaitForChild("Animator")
  2. local swim = script.Parent:WaitForChild("Animations"):FindFirstChild("Swim")
  3. local anim = animcontroller:LoadAnimation(swim)
  4.  
  5. local shark = script.Parent
  6. local primaryPart = shark.PrimaryPart or shark:WaitForChild("HumanoidRootPart")
  7. local speed = 10
  8. local chaseSpeed = 17.5
  9. local chasing = false
  10. local chaseCooldown = false
  11. local waypoints = workspace:WaitForChild("SharkWayPoints"):GetChildren()
  12. table.sort(waypoints, function(a, b) return a.Name < b.Name end)
  13.  
  14. local currentWaypointIndex = 1
  15. local vel = Instance.new("BodyVelocity")
  16. vel.MaxForce = Vector3.new(10000, 10000, 10000)
  17. vel.Parent = primaryPart
  18.  
  19. anim:Play()
  20. anim:AdjustSpeed(1)
  21.  
  22. local function moveToPosition(targetPosition, moveSpeed)
  23. local direction = (targetPosition - primaryPart.Position).Unit
  24. primaryPart.CFrame = CFrame.lookAt(primaryPart.Position, targetPosition) * CFrame.Angles(0, math.rad(180), 0)
  25. vel.Velocity = direction * moveSpeed
  26. end
  27.  
  28. local function moveToWaypoint()
  29. if not chasing then
  30. local target = waypoints[currentWaypointIndex]
  31. if target then
  32. moveToPosition(target.Position, speed)
  33. end
  34. end
  35. end
  36.  
  37. local function nextWaypoint()
  38. currentWaypointIndex = currentWaypointIndex + 1
  39. if currentWaypointIndex > #waypoints then
  40. currentWaypointIndex = 1
  41. end
  42. moveToWaypoint()
  43. end
  44.  
  45. local function chasePlayer(player)
  46. chasing = true
  47. local chaseTime = math.random(6, 10)
  48. local startTime = tick()
  49.  
  50. while chasing and tick() - startTime < chaseTime do
  51. if not player.Character or not player.Character:FindFirstChild("PrimaryPart") or player.Character:FindFirstChild("Humanoid").Health <= 0 then
  52. break
  53. end
  54. local playerPos = player.Character.PrimaryPart.Position
  55. moveToPosition(playerPos, chaseSpeed)
  56. anim:AdjustSpeed(1.75)
  57.  
  58. task.wait(0.1)
  59. end
  60.  
  61. chasing = false
  62. chaseCooldown = true
  63. anim:AdjustSpeed(1)
  64. moveToWaypoint()
  65. task.wait(chaseTime)
  66. chaseCooldown = false
  67. end
  68.  
  69. task.spawn(function()
  70. while true do
  71. if not chasing and not chaseCooldown then
  72. for _, player in pairs(game.Players:GetPlayers()) do
  73. local character = player.Character
  74. if character and character:FindFirstChild("PrimaryPart") then
  75. local distance = (character.PrimaryPart.Position - primaryPart.Position).Magnitude
  76. if distance <= 30 then
  77. chasePlayer(player)
  78. break
  79. end
  80. end
  81. end
  82. end
  83. if not chasing then
  84. local target = waypoints[currentWaypointIndex]
  85. if target and (primaryPart.Position - target.Position).Magnitude <= 5 then
  86. nextWaypoint()
  87. else
  88. moveToWaypoint()
  89. end
  90. end
  91. task.wait(0.1)
  92. end
  93. end)
  94.  
Advertisement
Add Comment
Please, Sign In to add comment