Recently I’ve been working on a game where having control over the celestial bodies (the sun and moon) is of utmost importance. As such I created a module that allows you to more easily set these values and also do some neat things like lerp between them.
local mouse = game.Players.LocalPlayer:GetMouse()
local CelestialBodyClass = require(game.ReplicatedStorage.CelestialBody)
local activeTween = nil
mouse.Button1Down:Connect(function()
if (activeTween) then
activeTween:Cancel()
end
local current = CelestialBodyClass.FromLighting("Sun")
local sun = CelestialBodyClass.FromDirection("Sun", mouse.UnitRay.Direction)
activeTween = CelestialBodyClass.Tween(current, sun, TweenInfo.new(3))
activeTween:Play()
end)
API:
--[[
API:
Static Functions:
CelestialBody.Tween(bodyA, bodyB, tweenInfo)
> Returns a pseudo tween object should behave identically to what TweenService:Create returns
CelestialBody.ToTimeOfDay(Number clockTime)
> Provide a clock time and the function will return the equivalent TimeOfDay String
CelestialBody.ToClockTime(String timeOfDay)
> Provide a time of day string and the function will return the equivalent ClockTime Number
Constructors:
CelestialBody.new(String body, Number timeOfDay, Number geographicLatitude)
> Creates a CelestialBodyClass from the body ("Sun" or "Moon"), time of day, and the geographic latitude
CelestialBody.FromLighting(String body)
> Creates a CelestialBodyClass from the body ("Sun" or "Moon") and the current Lighting properties
CelestialBody.FromDirection(String body, Vector3 direction)
> Creates a CelestialBodyClass from the body ("Sun" or "Moon") and a direction
> For example you could do this to match current lighting as well:
> CelestialBody.FromDirection("Sun", game.Lighting:GetSunDirection())
Methods:
CelestialBody:SetAsLighting()
> Sets the CelestialBody properties to the actual lighting
CelestialBody:GetDirection()
> Returns the direction of the CelestialBody
CelestialBody:Lerp(CelestialBody cBody, Number alpha)
> Returns a new CelestialBody which represents the interpolated information between CelestialBody and cBody by amount alpha
CelestialBody:Clone()
> Returns a duplicate of the current CelestialBody
Properties:
CelestialBody.Body
> Either the "Sun" or the "Moon"
CelestialBody.TimeOfDay
> The time of day string representing the CelestialBody
CelestialBody.GeographicLatitude
> The geographic latitude representing the CelestialBody
--]]
I haven’t really added any because I felt the methods and constructors were pretty self explanatory and familiar with stuff you already know e.g. :Lerp().
No unfortunately as you saw TweenService does not work with CelestialBodies. I’ve created a very simple “Pseudo Tween” which only allows very basic tween functionality.
One direction, only play or cancel, no repeat count or delay timer. Otherwise you have access to all the other stuff: Completed Event, EasingStyle, EasingDirection.
Of course you don’t need to use that. I provided a lerp method so you can write your tween setup if need be.
Is it possible to make sunlight come from below the horizon?
When I move the sun below the horizon light comes from the moon, as normal… I’ve tried using the moon class to move the sun and moon both below the horizon at the same time, but lighting still comes from above from either the moon or the sun from whichever I did last. Maybe I didn’t do it right, I just quickly tried the module and didn’t look into it too much.
No that’s not possible. The light source, the sun or moon, is always in the sky. They can’t both be below. This is a limitation of Roblox, not the module.
Tmk @Maximum_ADHD’s module doesn’t have the functionality to lerp/tween between celestial body states. That’s the main difference in usage between his plugin vs this module.
Honestly roblox’s celestial body system is extremely outdated in comparison to their new features and I really do hope they add onto it eventually. This is a pretty cool controller, and ver generous of you to provide it to the community in such a nice format!