How Can I check if the players camera is in line with the sun or moon?

I’ve looked at things like Lighting:GetSunDirection and CurrentCamera.CFrame.LookVector etc but I just dont know.

I want to make an effect where the more directly you look into the sun the more blurred it gets.

local dirSun = Lighting:GetSunDirection()
local dirCamera = workspace.CurrentCamera.CFrame.LookVector

The quick and dirty solution: check whether the two direction vectors are within 0.1 or so studs.

local d = 0.1 -- studs. how sensitive this is, from 0 to 1
return (dirSun - dirCamera).magnitude < d

The more informed solution is to calculate the angle between the two vectors and ask whether it is, say, less than 20 degrees.
The angle between two vectors is the arc-cosine of (their dot product, divided by the product of their magnitudes — in layman’s terms, their lengths multiplied)

local theta = 20 -- degrees
return math.acos(dirSun:Dot(dirCamera) / (dirSun.magnitude * dirCamera.magnitude) < math.rad(theta)

Because direction vectors’ lengths are always 1, the stuff after the / is always 1, and dividing by 1 does nothing, so that part can just be removed. And the angle does not change, so the stuff with the cosine and the conversion to radians can be performed just once, instead of every time you calculate that.

local theta = 20 -- degrees. from 0 to 180
theta = math.cos(math.rad(theta))
return dirSun:Dot(dirCamera) < theta -- is cosine of angle between camera and sun less than the cosine of 20 degrees?

This code has not been tested, report back if anything goes wrong

Could you explain to me what :Dot and math.acos do also how would I have like a twening effect so the closer to the center of the sun you look the more blurred it gets?

Example:

using v1:dot(v2) returns the dot product of vector3s v1 and v2, if you don’t know what the dot product is, this is a video explaining it. Essentially, you’re projecting one vector onto the other, but is has the very nice application of showing how closely the two vectors are pointing in the same direction. If they’re pointing in the same direction, the dot product is the product of their magnitudes, if they’re pointing in opposite directions, it’s the negative product of their magnitudes, and if they’re parallel, then it’s 0.

math.acos(n) returns the inverse cosine of number n, which will be an angle. If you don’t know trigonometry, the cosine function takes an angle, draws a line in that direction, and gives the ratio between the x value of a point on the line and the length of the line at that point.

what about my other question though

Also when I put it in a loop it creates tons of blureffects

also its affect by the amount of zoom and does not work when you are zoomed in close to character

still need help with this btw magnitude is not working