Hello,Im trying to make a 2D light system,The red lines are rays going into each corner in the room and the box, To make the light there i actually need to fill those ‘triangles’ with more frames making it fill the space
I have no idea how to achieve that and if its even possible
local Source = script.Parent:WaitForChild("Cube")
local run = game:GetService("RunService")
local Objects = {}
local World = script.Parent.Parent.Parent
local rayEngine = require(game.StarterGui:WaitForChild("RayCast2"))
for i,v in pairs(script.Parent:GetChildren()) do
if v.Name == "fram" then
table.insert(Objects,v)
elseif v.Name == "Obs" then
table.insert(Objects,v)
end
end
local function GetCorners(Element)
local LT = Vector2.new(Element.Position.X.Offset,Element.Position.Y.Offset)
local LB = Vector2.new(Element.Position.X.Offset,Element.Position.Y.Offset + Element.Size.Y.Offset)
local RT = Vector2.new(Element.Position.X.Offset + Element.Size.X.Offset,Element.Position.Y.Offset)
local RB = Vector2.new(Element.Position.X.Offset + Element.Size.X.Offset,Element.Position.Y.Offset + Element.Size.Y.Offset)
return {LT,LB,RT,RB}
end
wait(1)
run.RenderStepped:Connect(function()
for i,v in pairs(Objects) do
for i,v in pairs(GetCorners(v)) do
local x_center = Source.AbsolutePosition.X + (Source.AbsoluteSize.X / 2)
local y_center = Source.AbsolutePosition.Y + (Source.AbsoluteSize.Y / 2)
local ray = rayEngine.new(Vector2.new(x_center, y_center),Vector2.new(v.X,v.Y))
ray.Visible = true
local hit, pointPosition = ray:Cast(World, {World:GetDescendants()})
end
end
end)
I don’t have any super in-depth experience with this type of thing but perhaps you could try uploading a right angle triangle as an image and then use this right triangle to fill what needs to be filled. EgoMoose wrote a good article on how to fill in an arbitrary triangle using right-angle triangles, so this could probably work in your case as well.
I’ve worked with that article before so I can probably get a somewhat functional product with a lot of testing, let me know if this is something you’d be interested in.