I want to ensure the proportions for the beam’s width is the same as the lights, however I’m unsure as to what formula I’d use to get this value.
(This is somewhat related to my previous post)
I do have access to the variable regarding the distance between the origin and the floor. I also have all the light’s properties, such as range, angle etc. I also do have the positions for the origin and the floor.
I’ve included an image that demonstrates what I’m trying to achieve
(Red is what I want the width to be, blue is what it currently is)
What I think is that every 1 stud the brightness lowers so if u do
local lightpart = -- path to light emitting part
local calculationpart = -- path to the part that will be used to get the distance
local dist = (lightpart.Position-calculationpart.Position).Magnitude -- lets say its 10
local brightness = 16 -- for now its 16
-- brightness-dist ???
This is kind of a shot in the dark (no pun intended), but you can try multiplying the width of the beam by the light sources range * 2.
If you wanted to get fancy you could also theoretically incorporate the angle but math was has never been my friend so this is the best idea I can provide.
That worked! Here’s the result + implementation to the final code.
local caster = Light.Parent
local origin = caster
local function GetPartsInFrontRay(start)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {start}
params.FilterType = Enum.RaycastFilterType.Blacklist
local vector = start.CFrame.LookVector
local ray = workspace:Raycast(start.Position, vector * Light.Range, params)
if ray and ray.Instance then
return ray.Instance
end
end
while task.wait(.05) do
local part = GetPartsInFrontRay(origin)
if part then
local distance = origin.Position.Magnitude - part.Position.Magnitude
caster.Bottom.Position = part.Position
caster.Dust.Size = Vector3.new(caster.Dust.Size * 1)
caster.Top.Ray.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, Light.Color),
ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 0, 0))
}
local lightpart = caster
local calculationpart = part
local dist = (lightpart.Position-calculationpart.Position).Magnitude
local brightness = Light.Brightness
caster.Top.Ray.Width1 = dist
end
end```