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)
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:
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