Hello, I am trying to make a mirror and when you shoot it with a laser, the laser beam reflects. I have the shooting part done, but can’t seem to figure out how to reflect it.
I’ve tried some solutions on devforum posts but it doesn’t work and I cannot figure out the math.
LocalScript code.
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
UIS.InputBegan:Connect(function(input, gPe)
if gPe then return end
if input.KeyCode == Enum.KeyCode.Q then
local ray = game.Players.LocalPlayer:GetMouse().UnitRay
local _, position, normal = workspace:FindPartOnRay(ray, player.Character)
local hit = mouse.Target
print(hit)
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("White")
beam.Material = "Neon"
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
script.Laser:Play()
local distance = (mouse.Hit.p - position).magnitude
beam.Size = Vector3.new(0.1, 0.1, distance)
beam.CFrame = CFrame.new(mouse.Hit.p, position) * CFrame.new(0, 0, -distance / 2)
if hit then
if hit.Name == "Mirror" then
print("Hit mirror") -- no idea what to do after this point.
end
end
for i = 0,1,0.1 do
beam.Transparency = i
wait()
end
end
end)