How can I use trigonometry to find this angle?

I want to use trigonometry to find this angle I have looked at this thread:

But the code provided did not work:

local Adjacent = game.Players.LocalPlayer.Head.CFrame
local Hypotenuse = workspace.CurrentCamera.CFrame
--The both are CFrames, not Vectors, but it should help you to understand

local FinalVector = Adjacent:ToObjectSpace(Hypotenuse).LookVector --We need to make the 2 vectors relative, ldk as without this it dont work. Still Remember we are using 2 CFrames and the function only takes 1 Parameter

local Theta = math.acos(FinalVector)

Here is my angle

how can I find this angle please let me know and provide resources!

Here is my code right now

local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local LocalPlayerHead = LocalPlayerCharacter:WaitForChild("Head")
local CurrentCamera = workspace.CurrentCamera

function VisRay(RayNew)
	local my_ray = RayNew

	local part = Instance.new("Part")
	part.Anchored = true
	part.CFrame = CFrame.new(my_ray.Origin:Lerp(my_ray.Direction, 0.5), my_ray.Direction)
	part.Size = Vector3.new(1, 1, (my_ray.Origin - my_ray.Direction).Magnitude)
	part.Parent = workspace
end

local Magnitude = (Lighting:GetSunDirection() - CurrentCamera.CFrame.LookVector).Magnitude
print(math.deg(math.acos(Magnitude)))

I don’t believe that triangle is a right-angle triangle so you can’t directly use the code made by @Eternalove_fan32 to measure the angle between those two parts of using math.acos.

I suggest instead using vector trigonometry instead in the form of using the dot product between vectors as derived from the law of cosines mathematically as explained by this very helpful post by @ThanksRoBama:

Thanks RoBama

math.acos( a:Dot(b)/(a.Magnitude * b.Magnitude) )

Or if you use a CFrame look vector since CFrame vector components are unit vectors we can just do this which is very helpful to shorten code:

math.acos( a:Dot(b) )
2 Likes

Like this? But i dont know why its creating so many blureffects?

local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local CurrentCamera = workspace.CurrentCamera

local ViewSunDirection = false

while wait() do
	if ViewSunDirection and not Lighting:FindFirstChild("BlurEffect") then
		local BlurEffect = Instance.new("BlurEffect")
		BlurEffect.Parent = Lighting
	elseif Lighting:FindFirstChild("BlurEffect") then
		Lighting.Blur:Destroy()
	end
	
	local Difference = CurrentCamera.CFrame.Position - Lighting:GetSunDirection()
	local Degree = math.deg(math.atan2(Difference.X, Difference.Z))
	
	if Degree > 120 and Degree < 125 then
		ViewSunDirection = true
	else
		ViewSunDirection = false
	end
end

also that just gives this image

but you can split a regular triangle into 2 right-angle triangles, like egomoose do this!

1 Like

what do you exactly want to do?

when the player is looking at the sun it adds a blur effect

Then you may find this interesting:
https://github.com/boatbomber/Distortion-Screen-Rain/blob/master/ScreenRain.lua#L265
It adds dropplets if you look in the sky, but you can change this that it adds blur effect instead of waterdropplets!

(Credit to @boatbomber)

1 Like

I get it now but can you explain why you are using acos? And how is :Dot being used?

Hope this helps: