Is their A way To check If the User Is Looking At The Sun, like if their camera is Pointing to it

even as a strong coder ,I’m really Struggling to get this To work, I’m hoping to make an Advanced Rays System💡potentially, but My main Focus is Increasing Brightness when player looks at the sun OR some sort of blinding mechanic, Raycast?? i dont even know how i would do this, PLUS+ It needs to be adaptable since Their Is Day&night So The sun Changes Position

The Suns Position Changes :star2:, i have no idea How I’m going To Check its position in 3d space

2 Likes

This might help?

game.Lighting:GetSunDirection():Angle(game.Workspace.CurrentCamera.CFrame.LookVector) will get the angle between the sun and the direction the camera is looking, if the angle is 0 the camera is looking directly at the sun. the angle will be in cringe units, you can use math.deg() to convert it to degrees if needed

If anybody Else reads this And Wants A working Answer, Here is Snippit that functions

local Cam = workspace.CurrentCamera game:GetService(“RunService”).RenderStepped:Connect(function()
local NewVector = game:GetService(“Lighting”):GetSunDirection()
local SunRay = NewVector:Angle(Cam.CFrame.LookVector)
local Clamped = math.abs(math.clamp(SunRay,0,2))
if Clamped <= 0.52 then
warn(“Looking at sun”)
else
warn(“Not looking at sun”)
end
end)

1 Like