Is there a way to tell if a player is looking at the moon

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.

Any help would be appreciated.

I think you can use a combination of Lighting Properties and Camera:WorldToViewportPoint() to determine if the moon is on the screen.

Edit: Lighting has this method which seems perfect - GetMoonDirection

You can use this

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.

1 Like

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)

seems like @JarodOfOrbiter beat me lol

2 Likes