How to Create a Solar System on Roblox

How to Create a Solar System on Roblox By Tomroblox54321

In this tutorial I’m going to be show you how to make a simple or advanced Solar System on Roblox.

Note: For this tutorial it is recommended that you use my module [V2]Tomroblox54321’s Advanced Planetary Orbit Module or @daftcube’s module OrbitLib: Space Flight Dynamics for Roblox Lua. Mine is for easy yet moderately advanced orbits and @daftcube’s module is good for advanced but harder to set up.

For this tutorial I’m going to be using module for the scripts and examples. But do check out OrbitLib.

By the end of this you can create a solar system like this : Tomroblox54321’s Planetary Orbit Module. - YouTube

Setting up the Planets
So make what planets you want to have in the solar system and customize them. Something like this is great:

For this we have the Sun, Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune and Pluto.

I do recommend making the planets neon and making trails for the planet.

Scripting the Solar System
First get my module here : Tomroblox54321’s Advanced Planetary Orbit Module.
Get the module and import it into ServerScriptService.
Screen Shot 2022-04-02 at 10.43.47 PM

Next make a script for for one of your orbiting planets and type something like this into it.

local OrbitModule = require(game:GetService("ServerScriptService").OrbitModule)

local Sun = game.Workspace.Sun
local Earth = game.Workspace.Earth

local NewOrbit = OrbitModule:CircularOrbit(
	Earth,--Planet orbiting
	Sun,--Planet getting orbited
	10--Time to make a full orbit
)

If you want elliptical, eccentric or more advanced eccentric orbits, check my documentation on my module for more info!
Next for the moon make a script like this:

local OrbitModule = require(game:GetService("ServerScriptService").OrbitModule)

local Moon = game.Workspace.Moon
local Earth = game.Workspace.Earth

local NewOrbit = OrbitModule:CircularOrbit(
	Moon,--Planet orbiting
	Earth,--Planet getting orbited
	1--Time to make a full orbit
)

Then duplicate that script and change the parameters and planets to your chosen planets.

Now run it all and watch it go. It should now look like this!

And that’s it that’s how you make your own Solar System in Roblox Studio.

Hope you enjoyed this tutorial!

Tomroblox54321

20 Likes

Hello! This is amazing!
Is there a way to make the planets orbit horizontally instead of vertically around the sun? I have a spacecraft controller script which is really picky about aiming straight up.

Edit: I think I found a way: On Line 50 of your module, it has the XYZ figures,
local x = RadiusCosineMath(Angle)
local y = Radius
SineMath(Angle)
local z = 0

If you just sub out the Y for the Z and vice versa, it works like a charm, only it’s orbiting clockwise, which I’ll work on.

2 Likes

Wow, this is extremely good, it spins kinda quick though.

It’s really good, wow.

Can’t say much.

1 Like

Hey @Chamberlaine glad you are enjoying the module and tutorial. I have an eccentric a rough version for eccentric orbits. The orbits are at a different angle.

Would this help:

return function(PlanetOrbiting : PVInstance, PlanetGettingOrbited : PVInstance,Distance: number, Eccentricity : number, OrbitalPlane : number,Time: number)
	assert(PlanetOrbiting ~= PlanetGettingOrbited, "Cannot orbit itself, PlanetOrbiting and PlanetGettingOrbited should be different")

	local DifferenceVector = PlanetOrbiting:GetPivot().Position-PlanetGettingOrbited:GetPivot().Position --Differnce

	local Angle = Atan2Math(DifferenceVector.Y, DifferenceVector.X)--Angle
	local HeartbeatConnection
	HeartbeatConnection = RunService.Heartbeat:Connect(function(DeltaTime)
		local Dist = (PlanetOrbiting:GetPivot().Position-PlanetGettingOrbited:GetPivot().Position).Magnitude
		-- Disconnect the event if one of the planets got destroyed
		if not (PlanetOrbiting or PlanetGettingOrbited) then
			HeartbeatConnection:Disconnect()
			HeartbeatConnection = nil
		end

		-- Polar coordinates 2D
		local x
		local y
		local z = 0
		local offset
		if Eccentricity < 0 then
			x = (Distance+-Eccentricity)*CosineMath(Angle)
			y = (Distance+(-Eccentricity/2))*SineMath(Angle)
			offset = CFrame.new(Eccentricity/2,0,0)*CFrame.Angles(math.rad(OrbitalPlane)+math.rad(90),0,0)
		elseif Eccentricity == 0 then
			x = (Distance)*CosineMath(Angle)
			y = Distance*SineMath(Angle)
			offset = CFrame.new(Eccentricity,0,0)*CFrame.Angles(math.rad(OrbitalPlane)+math.rad(90),0,0)
		elseif Eccentricity > 0 then
			x = (Distance+Eccentricity)*CosineMath(Angle)
			y = (Distance+(Eccentricity/2))*SineMath(Angle)
			offset = CFrame.new(Eccentricity/2,0,0)*CFrame.Angles(math.rad(OrbitalPlane)+math.rad(90),0,0)
		end
		local cf = (CFrame.new(PlanetGettingOrbited.Position)*offset)*CFrame.new(x, y, z)
		PlanetOrbiting.Position = cf.Position
		local a = DeltaTime*TAU/Time
		Angle += a/Dist^DeltaTime
	end)
	--HeartbeatConnection:Disconnect()
	-- Return the heartbeat connection, so we can disconnect it if we no longer wants the part to orbit
	return HeartbeatConnection
end

If it’s spinning too fast just increase the orbital time.