Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a solid ray reflect of objects at 90 degrees?

Hello i've been at this for a while now to little success. I want to have a raycast hit a block and reflect of it at 90 degrees. Below is the current mess of code i've come up with but it does not work as intended.

local function createBeam(part, point, surfacePoint)
	print(part.Position)
	if surfacePoint then
		print(surfacePoint)
		  ray = Ray.new(point, surfacePoint * Vector3.new(1000,1000,1000))
	else
		print("no sp")
		  ray = Ray.new(point, part.CFrame.lookVector * Vector3.new(1000,1000,1000))
	end
	local newPart, newPoint, newSurfacePoint = workspace:FindPartOnRay(ray)

	local beam = Instance.new("Part", workspace:WaitForChild("Beams"))
	beam.BrickColor = BrickColor.new("Bright red")
	beam.FormFactor = "Custom"
	beam.Material = "Neon"
	beam.Transparency = 0.25
	beam.Anchored = true
	beam.Locked = true
	beam.CanCollide = false
	
	local distance = (point - newPoint).magnitude
	beam.Size = Vector3.new(0.3, 0.3, distance)
	beam.CFrame = CFrame.new(point, newPoint) * CFrame.new(0, 0, -distance / 2)
	
	if newPart then
		wait(0.5)
		createBeam(newPart, newPoint, newSurfacePoint)
	else
		print("Laser end")
	end
	wait(0.5)
end

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.