Skip to content

Instantly share code, notes, and snippets.

@mvyasu
Last active October 29, 2022 23:24
Show Gist options
  • Select an option

  • Save mvyasu/d048d2c1fa91c2e2d79dff26410095d4 to your computer and use it in GitHub Desktop.

Select an option

Save mvyasu/d048d2c1fa91c2e2d79dff26410095d4 to your computer and use it in GitHub Desktop.
A small module that contains some useful functions for manipulating celestial bodies.
--!strict
local atan2 = math.atan2
local sqrt = math.sqrt
local circleCircumference = math.pi*2
local function getGeoTimeForPointDirection(pointDirection: Vector3, longitudeFactor: number?): (number, number)
local realLongitudeFactor = longitudeFactor or -1
local latitude = atan2(pointDirection.Z, sqrt(pointDirection.X^2 + pointDirection.Y^2))
local longitude = atan2(pointDirection.Y * realLongitudeFactor, pointDirection.X * realLongitudeFactor)
local geoLatitude = (latitude/circleCircumference) * 360 + 23.5
local clockTime = ((longitude/circleCircumference) * 24 - 6) % 24
return geoLatitude, clockTime
end
local function getGeoTimeForInvertedBodies(): (number, number)
return getGeoTimeForPointDirection(game:GetService("Lighting"):GetSunDirection(), 1)
end
local function applyGeoTimeToLighting(geoLatitude: number, clockTime: number)
local Lighting = game:GetService("Lighting")
Lighting.GeographicLatitude = geoLatitude
Lighting.ClockTime = clockTime
end
return {
getGeoTimeForPointDirection = getGeoTimeForPointDirection,
getGeoTimeForInvertedBodies = getGeoTimeForInvertedBodies,
applyGeoTimeToLighting = applyGeoTimeToLighting,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment