Advertisement
GForcebit

Reflection

Mar 27th, 2021
3,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Debris=game:GetService("Debris")
  2. function raycast()
  3.     local part = owner.Character.Head
  4.     local visual = Instance.new("Part",owner.Character)
  5.     visual.Name = "Ray"
  6.     visual.Color =Color3.fromRGB(255, 255, 127)
  7.     visual.Material = Enum.Material.Neon
  8.     visual.CanCollide = false
  9.     visual.Anchored = true
  10.     visual.CFrame = part.CFrame
  11.     visual.Size = Vector3.new(.1,.1,.1)
  12.  
  13.     local currentPos = part.Position
  14.     local currentNormal = part.CFrame.LookVector
  15.     local laserdist = 1000
  16.     local function laser(distance)
  17.         local rayp = RaycastParams.new()
  18.                 rayp.FilterDescendantsInstances = {owner.Character}
  19.         rayp.FilterType = Enum.RaycastFilterType.Blacklist
  20.         rayp.IgnoreWater = true
  21.         local direction = currentNormal * (laserdist or  distance)
  22.         local raycastResult = workspace:Raycast(currentPos,direction)
  23.         local Pos
  24.         if raycastResult  then
  25.             Pos = raycastResult.Position
  26.         else
  27.             Pos = currentPos + direction
  28.         end
  29.         local clone = visual:Clone()
  30.         Debris:AddItem(visual,.5)
  31.         clone.Parent = owner.Character
  32.         clone.Size = Vector3.new(.5,.5,(currentPos-Pos).magnitude)
  33.         clone.CFrame = CFrame.new(currentPos:Lerp(Pos, 0.5), Pos)
  34.         Debris:AddItem(clone,.5)
  35.         local oldPos = currentPos
  36.         currentPos = Pos
  37.         if raycastResult then
  38.             local norm = raycastResult.Normal
  39.             local reflect = (currentNormal - (2 * currentNormal:Dot(norm) * norm))
  40.             currentNormal = reflect
  41.             laser(laserdist - (Pos-oldPos).Magnitude)
  42.             return
  43.         end
  44.     end
  45.     laser()
  46. end
  47. function Receive(plr,action,obj)
  48.     if action == "Down" then
  49.         raycast()
  50.     end
  51.  
  52. end
  53. local E = Instance.new("RemoteEvent",NLS([[local E = script:FindFirstChildWhichIsA("RemoteEvent")
  54.         local Mouse = owner:GetMouse()
  55.         function ButtonDown()
  56.         if Mouse.Target ~= nil then
  57.         E:FireServer("Down",Mouse.Target)
  58.         end
  59.         end
  60.         function ButtonUp()
  61.         E:FireServer("Up")
  62.         end
  63.         Mouse.Button1Down:Connect(ButtonDown)
  64.         Mouse.Button1Up:Connect(ButtonUp)
  65.         ]],owner.PlayerGui))
  66. E.OnServerEvent:Connect(Receive)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement