Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Plane = game.Workspace.Plane
- local PathFinding = game:GetService("PathfindingService")
- PathFinding.EmptyCutoff = 0
- local Start = Plane.PrimaryPart.Position
- local End = game.Workspace.Dest.Position
- local Path = PathFinding:ComputeSmoothPathAsync(Start, End, 500)
- local Points = Path:GetPointCoordinates()
- local EditedPoints = {}
- local DefaultHeight = Plane.PrimaryPart.Position.Y
- local AircraftHeight = 0
- local Speed = 2
- function RunPath()
- game.Workspace.Paths:ClearAllChildren()
- for _,v in pairs(Points) do
- v = Vector3.new(v.x, 0, v.z)
- table.insert(EditedPoints, Vector3.new(v.x, 0, v.z))
- local Part = Instance.new("Part")
- Part.FormFactor = Enum.FormFactor.Custom
- Part.Size = Vector3.new(1, 1, 1)
- Part.Position = v
- Part.Anchored = true
- Part.CanCollide = false
- Part.Parent = game.Workspace
- end
- for i,v in ipairs(EditedPoints) do
- if v ~= Points[1] and v ~= Points[#Points] then
- while (v - Plane.PrimaryPart.Position).magnitude > 3 do
- local EndRotation = math.deg(math.atan2(CFrame.new(Plane.PrimaryPart.Position, v).lookVector.x, CFrame.new(Plane.PrimaryPart.Position, v).lookVector.z))
- local Positive = math.deg(math.atan2((Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 5, 0)).lookVector.x, (Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 5, 0)).lookVector.z))
- local Negative = math.deg(math.atan2((Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, -5, 0)).lookVector.x, (Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, -5, 0)).lookVector.z))
- local Control = math.deg(math.atan2((Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 0)).lookVector.x, (Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 0)).lookVector.z))
- if Control > EndRotation - 1 and Control < EndRotation + 1 then
- Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 0))
- else
- if Control < EndRotation then
- Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, 0.005, 0))
- elseif Control > EndRotation then
- Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() * CFrame.Angles(0, -0.005, 0))
- end
- end
- Plane:SetPrimaryPartCFrame(Plane:GetPrimaryPartCFrame() + Plane:GetPrimaryPartCFrame().lookVector * 0.1)
- wait()
- end
- end
- end
- end
- RunPath()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement