Advertisement
AndrewTheMaster

Reflect

Jul 3rd, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. Player = game:GetService("Players").andrewengen1
  2. Button1Down = false
  3.  
  4.  
  5. function CalculateReflection(PointA, PointB, Hit, Distance)
  6. local Offset = Hit.CFrame:toObjectSpace(CFrame.new(PointB)).p
  7. local Face = nil
  8. local Largest = "x"
  9. if math.abs(Offset.y / Hit.Size.y) > math.abs(Offset.x / Hit.Size.x) then
  10. Largest = "y"
  11. end
  12. if math.abs(Offset.z / Hit.Size.z) > math.abs(Offset[Largest] / Hit.Size[Largest]) then
  13. Largest = "z"
  14. end
  15. if Offset[Largest] < 0 then
  16. if Largest == "x" then
  17. Face = "Left"
  18. elseif Largest == "y" then
  19. Face = "Bottom"
  20. elseif Largest == "z" then
  21. Face = "Back"
  22. end
  23. else
  24. if Largest == "x" then
  25. Face = "Right"
  26. elseif Largest == "y" then
  27. Face = "Top"
  28. elseif Largest == "z" then
  29. Face = "Front"
  30. end
  31. end
  32. local X, Y = CFrame.new(PointA, PointB):toEulerAnglesXYZ() --Vector3.new(Hit.CFrame:toEulerAnglesXYZ()).y???
  33. if Face == Enum.NormalId.Left.Name or Face == Enum.NormalId.Right.Name then
  34. return CFrame.new(PointB) * CFrame.fromEulerAnglesXYZ(X + math.rad(180), Y, 0)
  35. elseif Face == Enum.NormalId.Bottom.Name or Face == Enum.NormalId.Top.Name then
  36. return CFrame.new(PointB) * CFrame.fromEulerAnglesXYZ(-X + math.rad(180), -Y, 0)
  37. elseif Face == Enum.NormalId.Front.Name or Face == Enum.NormalId.Back.Name then
  38. return CFrame.new(PointB) * CFrame.fromEulerAnglesXYZ(-X, -Y, 0)
  39. end
  40. end
  41.  
  42.  
  43. function onSelected(Mouse)
  44. Mouse.Button1Down:connect(function()
  45. Button1Down = true
  46. while Button1Down do
  47. for _, Part in pairs(Player.Character:GetChildren()) do
  48. if Part.Name == "RayPart" then
  49. Part:Remove()
  50. end
  51. end
  52. local PointA = Player.Character.Torso.CFrame.p
  53. local PointB = Mouse.Hit.p
  54. for i = 1, 50 do
  55. local Ray = Ray.new((CFrame.new(PointA, PointB) * CFrame.new(0, 0, -0.1)).p, (PointB - PointA).unit * 300)
  56. local Hit, Position = game.Workspace:FindPartOnRay(Ray, Player.Character)
  57. local RayPart = Instance.new("Part", Player.Character)
  58. RayPart.Name = "RayPart"
  59. RayPart.BrickColor = BrickColor.new("Bright red")
  60. RayPart.Transparency = 0.5
  61. RayPart.Anchored = true
  62. RayPart.CanCollide = false
  63. RayPart.TopSurface = Enum.SurfaceType.Smooth
  64. RayPart.BottomSurface = Enum.SurfaceType.Smooth
  65. RayPart.FormFactor = Enum.FormFactor.Custom
  66. local Distance = (Position - PointA).magnitude
  67. RayPart.Size = Vector3.new(0.2, 0.2, Distance)
  68. RayPart.CFrame = CFrame.new(PointA, Position) * CFrame.new(0, 0, -Distance / 2)
  69. if Hit ~= nil then
  70. PointB = (CalculateReflection(PointA, Position, Hit, Distance) * CFrame.new(0, 0, 1)).p
  71. PointA = Position
  72. else
  73. break
  74. end
  75. end
  76. wait()
  77. end
  78. end)
  79. Mouse.Button1Up:connect(function()
  80. Button1Down = false
  81. end)
  82. end
  83.  
  84.  
  85. if script.Parent.ClassName ~= "HopperBin" then
  86. if Player == nil then print("Error: Player not found!") return end
  87. Tool = Instance.new("HopperBin")
  88. Tool.Name = "Laser"
  89. Tool.Parent = Player.Backpack
  90. script.Name = "Main"
  91. script.Parent = Tool
  92. elseif script.Parent.ClassName == "HopperBin" then
  93. Player = script.Parent.Parent.Parent
  94. script.Parent.Selected:connect(onSelected)
  95. --script.Parent.Deselected:connect(onDeselected)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement