Collapse Sidebar




The geographic latitude, in degrees, of the scene, influencing the result of Lightings time on the position of the sun and moon.

When calculating the position of the sun, the earth’s tilt is also taken into account.

Changing GeographicLatitude will alter the position of the sun at every Lighting/TimeOfDay. Developers looking to obtain the sun or moon’s position should use Lighting/GetSunDirection or Lighting/GetMoonDirection.

Code Samples

Sun direction

The following code sample is an example of the how the direction of the sun is calculated. This is the calculation that Lighting/GetSunDirection uses.

local lighting = game:GetService("Lighting")
local unitZ = Vector3.new(0,0,1)
local earthTilt = math.rad(23.5) -- The Earth's tilt in radians.
local halfSolarYear = 182.6282 -- Half the length of an average solar year
local function getSunDirection()
	local gameTime = lighting:GetMinutesAfterMidnight()
	local geoLatitude = lighting.GeographicLatitude
	local dayTime = gameTime/1440
	local sourceAngle = 2 * math.pi * dayTime
	local sunPosition = Vector3.new(math.sin(sourceAngle), -math.cos(sourceAngle), 0)
	local latRad = math.rad(geoLatitude)
	local sunOffset = -earthTilt * math.cos(math.pi * (dayTime - halfSolarYear) / halfSolarYear) - latRad
	local sunRotation = CFrame.fromAxisAngle(unitZ:Cross(sunPosition), sunOffset)
	local sunDirection = sunRotation * sunPosition
	return sunDirection