Hello, I am working on a game and want to create a kind of beam of light stretching across 2 parts that looks similar to an instance light, like a point light or a surface light but I can’t find anything that helps me.
Here is an image of what I want to achieve:
I have tried using a script to make an invisible Part that stretches across that line and puts a SurfaceLight in it facing down, but I can’t seem to make the part stretch diagonally.
Basically, I fit a part between the two points. Then, I divide the part into sections based off how large you want the lights to be. Then I make an attachment in the part with a point light per section.
Here’s my script:
local LightWidth = 10 -- How wide the light goes
local Folder = script.Parent
local Part = Folder.Part
local PointA = Folder.a.Position
local PointB = Folder.b.Position
local Distance = (PointA - PointB).Magnitude
local Size = Vector3.new(.1, .1, Distance)
local Cframe = CFrame.new(PointA, PointB) * CFrame.new(0, 0, -Distance/2)
local FrontOfPart = (Cframe * CFrame.new(0,0,-Distance/2)).p
local BackOfPart = (Cframe * CFrame.new(0,0,Distance/2)).p
Part.Size = Size
Part.CFrame = Cframe
local NumberOfLights = Distance/LightWidth
for i = 1,NumberOfLights do
local Position = FrontOfPart:Lerp(BackOfPart,(i/NumberOfLights))
local Attachment = Instance.new("Attachment")
Attachment.Parent = Part
Attachment.WorldPosition = Position
local Light = Instance.new("PointLight")
Light.Parent = Attachment
Light.Range = LightWidth
Light.Brightness = 10
end
How my workspace is set up:
(“part” is the part thats being stretched between the two points)