KrYn0MoRe

reflection

May 10th, 2021 (edited)
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.65 KB | None | 0 0
  1. Model0 = Instance.new("Model")
  2. Part1 = Instance.new("Part")
  3. Part2 = Instance.new("Part")
  4. Part3 = Instance.new("Part")
  5. Part4 = Instance.new("Part")
  6. Part5 = Instance.new("Part")
  7. Model0.Parent = script
  8. Part1.Parent = Model0
  9. Part1.CFrame = CFrame.new(0.349994659, 20.5, 35, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  10. Part1.Position = Vector3.new(0.34999465942383, 20.5, 35)
  11. Part1.Size = Vector3.new(88.900001525879, 41, 2)
  12. Part1.Anchored = true
  13. Part1.BottomSurface = Enum.SurfaceType.Smooth
  14. Part1.TopSurface = Enum.SurfaceType.Smooth
  15. Part2.Parent = Model0
  16. Part2.CFrame = CFrame.new(-3.45000005, 20.5, -40.1999969, -1, 0, 0, 0, 1, 0, 0, 0, -1)
  17. Part2.Orientation = Vector3.new(0, 180, 0)
  18. Part2.Position = Vector3.new(-3.4500000476837, 20.5, -40.199996948242)
  19. Part2.Rotation = Vector3.new(-180, 0, -180)
  20. Part2.Size = Vector3.new(88.900001525879, 41, 2)
  21. Part2.Anchored = true
  22. Part2.BottomSurface = Enum.SurfaceType.Smooth
  23. Part2.TopSurface = Enum.SurfaceType.Smooth
  24. Part3.Parent = Model0
  25. Part3.CFrame = CFrame.new(-38.5999908, 20.5, -8.05000591, 0, 0, -1, 0, 1, 0, 1, 0, 0)
  26. Part3.Orientation = Vector3.new(0, -90, 0)
  27. Part3.Position = Vector3.new(-38.599990844727, 20.5, -8.0500059127808)
  28. Part3.Rotation = Vector3.new(0, -90, 0)
  29. Part3.Size = Vector3.new(88.900001525879, 41, 2)
  30. Part3.Anchored = true
  31. Part3.BottomSurface = Enum.SurfaceType.Smooth
  32. Part3.TopSurface = Enum.SurfaceType.Smooth
  33. Part4.Parent = Model0
  34. Part4.CFrame = CFrame.new(-4.35000801, 39.6999969, -5.3499999, 0, -1, 0, 0, 0, -1, 1, 0, 0)
  35. Part4.Orientation = Vector3.new(90, -90, 0)
  36. Part4.Position = Vector3.new(-4.3500080108643, 39.699996948242, -5.3499999046326)
  37. Part4.Rotation = Vector3.new(90, 0, 90)
  38. Part4.Size = Vector3.new(99.099998474121, 88.699996948242, 2)
  39. Part4.Anchored = true
  40. Part4.BottomSurface = Enum.SurfaceType.Smooth
  41. Part4.TopSurface = Enum.SurfaceType.Smooth
  42. Part5.Parent = Model0
  43. Part5.CFrame = CFrame.new(40.3000031, 20.5, -4.05000639, 0, 0, 1, 0, 1, 0, -1, 0, 0)
  44. Part5.Orientation = Vector3.new(0, 90, 0)
  45. Part5.Position = Vector3.new(40.300003051758, 20.5, -4.0500063896179)
  46. Part5.Rotation = Vector3.new(0, 90, 0)
  47. Part5.Size = Vector3.new(88.900001525879, 41, 2)
  48. Part5.Anchored = true
  49. Part5.BottomSurface = Enum.SurfaceType.Smooth
  50. Part5.TopSurface = Enum.SurfaceType.Smooth
  51.  
  52. local offset = Vector3.new(0,0,-50)
  53. local maxsize = 5
  54.  
  55. for i,v in pairs(script.Model:GetChildren()) do
  56.     if v:IsA("Part") then
  57.         v.Transparency = 0.5
  58.         v.CanCollide = false
  59.         v.Position = v.Position+offset
  60.     end
  61. end
  62.  
  63. local sfx = {
  64.     crack = {
  65.         151284431,
  66.         259586543,
  67.     },
  68.     hit = {
  69.         3092866899,
  70.     }
  71. }
  72.  
  73. local pf = Instance.new("Folder",script)
  74.  
  75. function raycast(Pos, Dir, Max, Ignore)
  76.     local rayparams = RaycastParams.new()
  77.     rayparams.FilterType = Enum.RaycastFilterType.Blacklist
  78.     rayparams.FilterDescendantsInstances = Ignore
  79.     rayparams.IgnoreWater = true
  80.     return workspace:Raycast(Pos, Dir * (Max or 999.999), rayparams)
  81. end
  82.  
  83. local speed = 50
  84.  
  85. function reflect(pos,n,attempts,ignore)
  86.     ignore = ignore or {pf}
  87.     attempts = attempts or 0
  88.     if attempts >= 5 then return end
  89.     local m1,m2,m3 = math.random(),math.random(),math.random()
  90.     if math.random(1,2) == 1 then
  91.         m1 = -m1
  92.     end
  93.     if math.random(1,2) == 1 then
  94.         m2 = -m2
  95.     end
  96.     if math.random(1,2) == 1 then
  97.         m3 = -m3
  98.     end
  99.     n = n or Vector3.new(m1,m2,m3)
  100.     local result = raycast(pos,n,nil,ignore)
  101.     if result and 1 > result.Instance.Transparency --[[and result.Instance.CanCollide]] then
  102.         local char = result.Instance.Parent
  103.         local root = char:FindFirstChild("HumanoidRootPart")
  104.         local hum = char:FindFirstChildOfClass("Humanoid")
  105.         if root and hum then
  106.             hum:TakeDamage(30)
  107.             local hitfx = Instance.new("Sound")
  108.             hitfx.SoundId = 'rbxassetid://' .. sfx.hit[math.random(1,#sfx.hit)]
  109.             hitfx.Volume = 0.5
  110.             hitfx.Parent = root
  111.             hitfx:Play()
  112.             game:GetService("Debris"):AddItem(hitfx,1)
  113.         end
  114.     else
  115.         attempts = attempts + 1
  116.         if result then
  117.             ignore = {result.Instance,unpack(ignore)}
  118.         end
  119.         reflect(pos,n,attempts,ignore)
  120.         return
  121.     end
  122.     local newn = n-(2*n:Dot(result.Normal)*result.Normal)
  123.     n = newn
  124.     local dist = (pos-result.Position).Magnitude
  125.     local rs = dist/speed
  126.    
  127.     local npart = Instance.new("Part")
  128.     npart.Size = Vector3.new()
  129.     npart.CanCollide = false
  130.     npart.Anchored = true
  131.     npart.Position = result.Position
  132.     npart.Transparency = 1
  133.     npart.Parent = pf
  134.     local ricofx = Instance.new("Sound")
  135.     ricofx.SoundId = 'rbxassetid://' .. sfx.crack[math.random(1,#sfx.crack)]
  136.     ricofx.Volume = 1
  137.     ricofx.Parent = npart
  138.     ricofx:Play()
  139.    
  140.     local reflection = Instance.new("Part")
  141.     reflection.CFrame = CFrame.new(pos,result.Position)*CFrame.Angles(math.rad(90),0,0)*CFrame.new(0,0,0)
  142.     reflection.Size = Vector3.new(0.1,0,0.1)
  143.     reflection.Color = Color3.new(1,0,0)
  144.     reflection.Material = Enum.Material.Neon
  145.     reflection.Anchored = true
  146.     reflection.CanCollide = false
  147.     reflection.Transparency = 0
  148.     reflection.Parent = pf
  149.     game:GetService("TweenService"):Create(reflection,TweenInfo.new(rs/2),{
  150.         CFrame = CFrame.new(pos,result.Position)*CFrame.Angles(math.rad(90),0,0)*CFrame.new(0,-(dist-maxsize/2),0),
  151.         Size = Vector3.new(0.1,maxsize,0.1),
  152.     }):Play()
  153.     game:GetService("TweenService"):Create(reflection,TweenInfo.new(rs),{
  154.         Transparency = 1,
  155.         Color = Color3.new(),
  156.     }):Play()
  157.     wait(rs/2)
  158.     game:GetService("TweenService"):Create(reflection,TweenInfo.new(rs/2),{
  159.         CFrame = CFrame.new(pos,result.Position)*CFrame.Angles(math.rad(90),0,0)*CFrame.new(0,-dist,0),
  160.         Size = Vector3.new(0.1,0,0.1),
  161.     }):Play()
  162.  
  163.     game:GetService("Debris"):AddItem(reflection,rs)
  164.     game:GetService("Debris"):AddItem(npart,rs)
  165.    
  166.     reflect(result.Position,n)
  167. end
  168.  
  169. for i = 1,10 do
  170.     coroutine.wrap(function()
  171.         reflect(Vector3.new(0,5,0)+offset)
  172.     end)()
  173. end
Add Comment
Please, Sign In to add comment