I actually don’t know how to title this topic, since I’m not sure what the issue is. Anyway I’m trying to achieve a more realistic look to lighting. Of course that comes with a price to pay, pain. So, I have took it upon my self to get this done. To be more precise, when it’s raining, you have dots on your vision. If you are looking at a light, those dots get brighter near that light. I got that effect working for one light, but I’m not sure how to get it working for multiple. Here is my piece of code:
--Some Vars
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
wait(3)--for now to let things load
local Player = Players.LocalPlayer
--Params
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
RayParams.FilterDescendantsInstances = {Player.Character}
--Tables
local sign = {
}
local WPoints = {
}
--Add world point and clone Guis to light amount
local RealismLighting = workspace:WaitForChild("RealismLighting")
repeat wait() until #RealismLighting:GetChildren() > 0
RealismLighting = RealismLighting:GetChildren()
for lightNum, light in pairs(RealismLighting) do
light.Name = "Pain" .. tostring(lightNum)
local WP = Vector3.new(light.Nothing.Position.X,light.Nothing.Position.Y-1,light.Nothing.Position.Z)
table.insert(WPoints, WP)
Gui = game.StarterGui.ScreenGui.Frame:Clone()
Gui.Parent = Player.PlayerGui.ScreenGui
Gui.Name = "Pain" .. tostring(lightNum)
end
--Getting Hexagons
local RealismLighting = Player.PlayerGui:WaitForChild("ScreenGui")
repeat wait() until #RealismLighting:GetChildren() > 0
RealismLighting = RealismLighting:GetChildren()
for lightNum, light in pairs(RealismLighting) do
if #light:GetChildren() >0 then
table.insert(sign, light)
else
end
end
--Calculating distance between world point and hexagon
local function Distance(Pos,depth)
for i,v in pairs(sign) do
local UdimPos = Vector2.new(v.ImageLabel.Position.X.Scale,v.ImageLabel.Position.Y.Scale)
local distance = (v.ImageLabel.AbsolutePosition - Pos).magnitude
v.ImageLabel.ImageTransparency = distance/500 * (depth/12) --math
end
end
--Check if world point is visible
local function PointinView(worldPoint)
local camera = workspace.CurrentCamera
for i,Point in pairs(worldPoint)do
local vector, onScreen = camera:WorldToViewportPoint(Point)
--Check if world point is on screen
if onScreen then
--cast ray
local origin = camera.CFrame.Position
local ray = workspace:Raycast(origin, Point - origin,RayParams)
OnScreenPos = Vector2.new(vector.X,vector.Y)
--Check if object is in way
if not ray then
--ray not hit
Gui.Position = UDim2.new(0,vector.X,0,vector.Y)
Distance(OnScreenPos,vector.Z)
else
--ray hit
Gui.Position = UDim2.new(0,10000,0,10000)
Distance(Vector2.new(1000,2000),10000)
end
else
Distance(OnScreenPos,100000)
end
end
end
--Call function
RunService.RenderStepped:Connect(function()
--while wait(1) do
PointinView(WPoints)
end)
It’s very garbage but it works, for one light. Here is how everything looks in the explorer:
Here is how it looks while in game:
That was the only difference
Here is a video for reference:
Thank you for reading.