Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. local Plane = game.Workspace.Plane
  2. local PathFinding = game:GetService("PathfindingService")
  3. PathFinding.EmptyCutoff = 0
  4. local Start = Plane.PrimaryPart.Position
  5. local End = game.Workspace.Dest.Position
  6. local Path = PathFinding:ComputeSmoothPathAsync(Start, End, 500)
  7. local Points = Path:GetPointCoordinates()
  8. local EditedPoints = {}
  9. local DefaultHeight = Plane.PrimaryPart.Position.Y
  10. local AircraftHeight = 0
  11. local Speed = 2
  12.  
  13. function RunPath()
  14. game.Workspace.Paths:ClearAllChildren()
  15.  
  16. for _,v in pairs(Points) do
  17. v = Vector3.new(v.x, 0, v.z)
  18. table.insert(EditedPoints, Vector3.new(v.x, 0, v.z))
  19. local Part = Instance.new("Part")
  20. Part.FormFactor = Enum.FormFactor.Custom
  21. Part.Size = Vector3.new(1, 1, 1)
  22. Part.Position = v
  23. Part.Anchored = true
  24. Part.CanCollide = false
  25. Part.Parent = game.Workspace
  26. end
  27.  
  28. for i,v in ipairs(EditedPoints) do
  29. if v ~= Points[1] and v ~= Points[#Points] then
  30. while (v - Plane.PrimaryPart.Position).magnitude > 3 do
  31. local EndRotation = math.deg(math.atan2(CFrame.new(Plane.PrimaryPart.Position, v).lookVector.x, CFrame.new(Plane.PrimaryPart.Position, v).lookVector.z))
  32. local Positive = math.deg(math.atan2((Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 5, 0)).lookVector.x, (Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 5, 0)).lookVector.z))
  33. local Negative = math.deg(math.atan2((Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, -5, 0)).lookVector.x, (Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, -5, 0)).lookVector.z))
  34. local Control = math.deg(math.atan2((Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 0)).lookVector.x, (Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 0)).lookVector.z))
  35.  
  36. if Control > EndRotation - 1 and Control < EndRotation + 1 then
  37. Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 0))
  38. else
  39. if Control < EndRotation then
  40. Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 0.005, 0))
  41. elseif Control > EndRotation then
  42. Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, -0.005, 0))
  43. end
  44. end
  45.  
  46. Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() + Plane:GetPrimaryPartCFrame().lookVector * 0.1)
  47. wait()
  48. end
  49. end
  50. end
  51. end
  52.  
  53. RunPath()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement