Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local center_part = Instance.new("Part")
- center_part.Size = Vector3.new(1,1,1)
- center_part.Anchored = true
- center_part.CanCollide = true
- center_part.Parent = script
- local offset = CFrame.new(20,20,0)
- center_part.CFrame = offset
- local target_part = center_part:Clone()
- target_part.Parent = script
- local hyp_part = center_part:Clone()
- hyp_part.Transparency = 0.5
- hyp_part.Color = Color3.new(1,0,0)
- hyp_part.Parent = script
- local adj_part = center_part:Clone()
- adj_part.Transparency = 0.5
- adj_part.Color = Color3.new(0,1,0)
- adj_part.Parent = script
- local opp_part = center_part:Clone()
- opp_part.Transparency = 0.5
- opp_part.Color = Color3.new(0,0,1)
- opp_part.Parent = script
- local at1 = Instance.new("Attachment")
- at1.Position = Vector3.new(0,-0.5,0)
- at1.Parent = target_part
- local at2 = Instance.new("Attachment")
- at1.Position = Vector3.new(0,0.5,0)
- at2.Parent = target_part
- local trail = Instance.new("Trail")
- trail.Attachment0 = at1
- trail.Attachment1 = at2
- trail.FaceCamera = true
- trail.Transparency = NumberSequence.new(0,1)
- trail.Lifetime = 1
- trail.MinLength = 0
- trail.WidthScale = NumberSequence.new(1,1)
- trail.Parent = target_part
- local angle_change = nil
- local hyp_mult = 1
- function update()
- local speed = 5
- local dist = 10
- local t = os.clock()*speed
- target_part.CFrame = offset*CFrame.new(0,math.cos(t)*dist,math.sin(t)*dist)
- local pos_sub = (center_part.Position-target_part.Position)*Vector3.new(0,1,1)
- local hyp = pos_sub.Magnitude
- if 0 > pos_sub.Y and hyp_mult == 1 then
- hyp_mult = -1
- local s = Instance.new("Sound")
- s.SoundId = 'rbxassetid://2687161647'
- s.Volume = 0.5
- s.PlayOnRemove = true
- s.Parent = target_part
- s:Destroy()
- elseif pos_sub.Y > 0 and hyp_mult == -1 then
- hyp_mult = 1
- local s = Instance.new("Sound")
- s.SoundId = 'rbxassetid://9111926008'
- s.Volume = 0.5
- s.PlayOnRemove = true
- s.Parent = target_part
- s:Destroy()
- end
- hyp = hyp*hyp_mult
- local adj = pos_sub.Z
- -- cosA = adj/hyp, A = arccos(adj/hyp)
- local angle = math.acos(adj/hyp)
- angle_change = angle
- -- sinA = opp/hyp, opp = hyp*sin(angle)
- local opp = hyp*math.sin(angle)
- hyp_part.Size = Vector3.new(1,1,math.abs(hyp))
- hyp_part.CFrame = offset*CFrame.new(0,-pos_sub.Y/2,-pos_sub.Z/2)*CFrame.Angles(angle*-1,0,0)
- adj_part.Size = Vector3.new(1,1,math.abs(adj))
- adj_part.CFrame = offset*CFrame.new(0,0,-pos_sub.Z/2)*CFrame.Angles(0,0,0)
- opp_part.Size = Vector3.new(1,math.abs(opp),1)
- opp_part.CFrame = offset*CFrame.new(0,-pos_sub.Y/2,-pos_sub.Z)*CFrame.Angles(0,0,0)
- end
- while true do
- task.wait()
- update()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement