Hello, I work on a big game project and I wonder how would I check if the player is looking at the sun.
My idea here is to create a GUI effect of sunshine that pops up when you look at the sun.
I already created the effect. Now, I need to get it working. Any idea how?
And if not, I really wouldn’t suggest trying to get this working. I wouldn’t even know where to start.
It’s one of the many limitations of Roblox. There is no API for detecting the current position of the sun on the screen. I imagine you could hard code this with a lot of effort, but it would be approximate at best and be extremely fragile.
I do not recommend pursuing a custom implementation, at all.
See below. Forgot :GetSunDirection() exists.
You’ll need to familiarise yourself with dot products, though.
Answering your question with the given context I would probably start with game.Lighting:GetSunDirection() and using :Dot
local sunDirection = game.Lighting:GetSunDirection()
local angle = 20
angle = math.cos(math.rad(angle))
game["Run Service"].RenderStepped:Connect(function(dt)
local directionCamera = workspace.CurrentCamera.CFrame.LookVector
if sunDirection:Dot(directionCamera) >= angle then
print("woah im like, super looking at the sun")
else
print("depression i am not looking at the sun")
end
end