I’m trying to make a great ape form for my dragon ball game but I want to make it so you have to look at the moon to be able to use it. At first i was planning to use Mouse.Target to check if the mouse is directly over the moon, but I don’t know how to tell if it is because I don’t know how to find it or where it is.
local angle = math.deg(math.acos(Workspace.CurrentCamera.CFrame.LookVector:Dot(game.Lighting:GetMoonDirection())))
In a LocalScript obviously because we’re working with the camera. It will give you the angle between the players view and the moon. Then check if it’s less than 10 degrees and fine tune that number until it feels right.
I didn’t know GetMoonDirection was a thing, so thanks for that.
Here is a little script I made. Should work if I got the math right:
local RunService = game:GetService("RunService")
local Lighting = game:GetService("Lighting")
RunService.RenderStepped:Connect(function()
local moonDirection = Lighting:GetMoonDirection().Unit
local camLookVector = workspace.Camera.CFrame.LookVector
local dotProduct = moonDirection:Dot(camLookVector)
if dotProduct >= 0.99 then
print("LOOKING AT MOON")
end
end)