Celestial Body Controller

Hi there,

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.

You can find the module here:

https://www.roblox.com/library/4848939768/CelestialBodyController

Example of what you can do with it:

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
--]]
64 Likes

Thanks, this will be very useful for me!

1 Like

Once again ego, you’ve outdone your self. I have a great game idea for this. :wink:

2 Likes

Where is the documentation? Sry if its in the module, bec i am on mobile, so I cant check it.

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().

I’ll go ahead and add that though real quick.

Edit: Added it!

3 Likes

Under the surface, are you using TweenService? I can never get it to cooperate when using celestial bodies :stuck_out_tongue:

I’m gonna put this module to use though! Thanks

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.

1 Like

Alright, so I caved and changed things around so now the tween can be fed a TweenInfo and work through the TweenService.

2 Likes

Wow! I thought you couldn’t tween the sun at all! I’m really happy that you constantly make new things for budding developers to use.

1 Like

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.

Thanks @EgoMoose, but can you make this/is this opensource?

Uh yeah… It already is… Click the link to add to your inventory.

1 Like

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.

2 Likes

I was thinking about making it tween while dragging to make it look cooler lol.

2 Likes

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!

2 Likes

instead of changing the suns positon to the horizon, could you change the horizons position to the sun ?
(upside-down)

Regarding your twitter post:

You inversed the time of day & geographic latitude, right? If so, any tips on figuring out the conversions?