I’ve done a bit of looking around and haven’t found anything about this topic.
When the player looks at or near the sun, I want to blind the player (I’ll probably mess around with depth of field or blur properties)
The problem is, I don’t know how to detect when the player is looking at or near the sun. Is there a way to calculate the position of the sun using lighting properties like TimeOfDay and GeographicLatitude?
Add a new script into StarterPlayerScripts, and paste this inside:
--//Services
local Lighting = game:GetService("Lighting")
--//Variables
local CurrentCamera = workspace.CurrentCamera
--//Controls
local theta = 20
theta = math.cos(math.rad(theta))
--//Loopds
while task.wait(0.5) do
local dirSun = Lighting:GetSunDirection()
local dirCamera = CurrentCamera.CFrame.LookVector
if dirSun:Dot(dirCamera) >= theta then
print("Player is looking at sun")
--//Run code
else
print("Player is not looking at sun")
end
end
You can use :Dot to check the angle between the camera’s LookVector and the sun’s direction.