-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfly-points.lua
117 lines (105 loc) · 2.75 KB
/
fly-points.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
--[==[HELP]==
[1] - {CFrame | Vector3 | BasePart | Model | {CFrame | Vector3 | BasePart | Model, number}}
Array of locations or two-element sub-arrays, where second element is the delay.
[2] - number | nil
The speed at which to fly; defaults to 139.
[3] - number | nil
Number of types to traverse the points; defaults to 1.
If less than 0, loops infinitely.
[4] - number | nil
Threshold to which next point can begin being reached; defaults to 13.
[5] - number | nil
Number of initial stops to skip; defaults to 0.
When going in reverse, skips last N stops in array.
[6] - bool | nil
If true, iterates the array of locations in reverse after sequence is finished.
]==] --
--
local args = _E and _E.ARGS or {}
local ch = game.Players.LocalPlayer.Character
local array = args[1]
local speed = args[2] or 139
local times = args[3] or 1
local dist = args[4] or 13
local skip = args[5] or 0
local shuttle = args[6]
function r_move_part(array, rp, p, v)
if typeof(v) == 'Vector3' then
p.CFrame = CFrame.new(v)
elseif typeof(v) == 'Instance' then
if v:isA 'BasePart' then
p.CFrame = v.CFrame
elseif v:isA 'Model' then
p.CFrame = v:GetPivot()
end
elseif typeof(v) == 'CFrame' then
p.CFrame = v
end
end
function r_task(array, rp, p)
task.delay(.25, function() rp.TargetRadius = tick() % .5 + dist end)
rp.ReachedTarget:Wait()
end
function r_step(array, rp, p, v)
if typeof(v) == 'table' then
r_move_part(array, rp, p, v[1])
r_task(array, rp, p)
rp:Abort()
task.wait(v[2])
rp:Fire()
elseif typeof(v) == 'CFrame' then
r_move_part(array, rp, p, v)
r_task(array, rp, p)
end
end
function r_loop(array, rp, p)
rp:Fire()
while rp.Parent do
if times == 0 then break end
for i = 1 + skip, #array do r_step(array, rp, p, array[i]) end
times = times - 1
if shuttle then
-- if times == 0 then break end
for i = #array - skip, 1, -1 do r_step(array, rp, p, array[i]) end
-- times = times - 1
end
end
rp:Abort()
end
function cleanup()
if _G.fp_rp then
_G.fp_rp:Abort()
_G.fp_rp:Destroy()
_G.fp_rp = nil
end
if _G.fp_bg then
_G.fp_bg:Destroy()
_G.fp_bg = nil
end
if _G.fp_tr then
_G.fp_tr:Destroy()
_G.fp_tr = nil
end
end
cleanup()
if array then
_G.fp_rp = Instance.new(
'RocketPropulsion', ch:FindFirstChildWhichIsA 'Humanoid'.RootPart)
_G.fp_bg = Instance.new(
'BodyGyro', ch:FindFirstChildWhichIsA 'Humanoid'.RootPart)
_G.fp_rp.MaxTorque = Vector3.new(1e9, 1e9, 1e9)
_G.fp_tr = Instance.new('Part', _G.fp_rp)
_G.fp_tr.Transparency = 1
_G.fp_tr.Anchored = true
_G.fp_tr.CanCollide = false
_G.fp_rp.CartoonFactor = 1
_G.fp_rp.MaxSpeed = speed
_G.fp_rp.MaxThrust = 1e5
_G.fp_rp.ThrustP = 1e7
_G.fp_rp.TurnP = 5e3
_G.fp_rp.TurnD = 2e3
_G.fp_rp.Target = _G.fp_tr
task.wait()
r_loop(array, _G.fp_rp, _G.fp_tr)
end
cleanup()