[Tomroblox54321's Advanced Planetary Orbit Module Is Out]Tomroblox54321's Planetary Orbit Module

Tomroblox54321’s Planetary Orbit Module
This script was originally created by Codes Otaku on Youtube.(I highly suggest you check his channel out). I have turned it into an easy to use module script. Just saying he said gave me permission to post it here.This is my first post so tell me if I did anything wrong.

Link to the Module: Tomroblox54321's Planetary Orbit Module V2 - Roblox

An Example Script:(This is Earth orbiting the Sun)

local ServerScriptService = game:GetService("ServerScriptService")--Getting ServerScriptService

local OrbitModule = require(ServerScriptService:WaitForChild("OrbitModuleFancy"))--Getting the Module

local PlanetOrbiting = game.Workspace.Earth--Getting the Orbiting Planet
local PlanetGettingOrbited = game.Workspace.Sun--Getting the planet that is getting orbited
local TimeToOrbit = 10--Choosing how long it takes to do a full orbit

local NewOrbit = OrbitModule(PlanetOrbiting, PlanetGettingOrbited, TimeToOrbit)--Running the Module

Example Script 2 :(This is the Moon orbiting the Earth)

local ServerScriptService = game:GetService("ServerScriptService")--Getting ServerScriptService

local OrbitModule = require(ServerScriptService:WaitForChild("OrbitModuleFancy"))--Getting the Module

local NewOrbit = OrbitModule(game.Workspace.Moon, game.Workspace.Earth, .4)--Running the Module

You can do PVInstances or numbers instead of variables now but both work perfectly fine!

I hope you enjoy!

  • Was this Module Cool/Helpful?
  • Yes
  • No

0 voters

18 Likes

Does anyone have any feedback/comments?

Looks like the model is not for sale.
image

Oh ok. Will try to fix sorry about that!

I think I have fixed it lmk if it didn’t work.

I’m CodesOtaku, I love this module!
I made an improved version for you, feel free to use it :smiley:

Module script:

local RunService = game:GetService("RunService")

local CosineMath = math.cos
local SineMath = math.sin
local Atan2Math = math.atan2

local PIMath = math.pi
local TAU = 2*PIMath

return function(PlanetOrbiting : PVInstance, PlanetGettingOrbited : PVInstance, TimeToOrbit : number, NormalOffset : function)
	assert(PlanetOrbiting ~= PlanetGettingOrbited, "Cannot orbit itself, PlanetOrbiting and PlanetGettingOrbited should be different")

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

	local Angle = Atan2Math(DifferenceVector.Y, DifferenceVector.X)--Angle
	
	local HeartbeatConnection
	HeartbeatConnection = RunService.Heartbeat:Connect(function(DeltaTime)
		-- 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 = Radius*CosineMath(Angle)
		local y = Radius*SineMath(Angle)
		local z = NormalOffset and NormalOffset(Angle, x, y) or 0

		PlanetOrbiting:PivotTo(PlanetGettingOrbited.CFrame*CFrame.new(x, y, z))
		Angle += DeltaTime*TAU/TimeToOrbit
	end)
	
	-- Return the heartbeat connection, so we can disconnect it if we no longer wants the part to orbit
	return HeartbeatConnection
end

Example script:

local A = workspace.A -- Replace this with some part
local B = workspace.B -- Replace this with some another part
local Orbit = require(script.OrbitModule)

local orbitPeriod = 1 -- Seconds it takes to make 1 full turn
local orbit = Orbit(A, B, orbitPeriod) -- Start the orbit
task.wait(5) -- Wait 5 seconds
orbit:Disconnect() -- Cancel the orbit
2 Likes

can you please show us a example?

1 Like

Perhaps send a video, images???

1 Like

Hi Codes that’s really cool! Thanks for sharing and the positive feedback!

2 Likes

How would you go about and send a video since I’m incredibly new to the forums.

1 Like

Oh, I guess welcome to the forum!

Okay, so you would want to use your recorder, now record your ingame footage, stop when you’re done, now you can drag the MP4 file to the forum, and it should say “uploading … videoname” it should take a while and there you have a video!

1 Like

Ok thanks will try asap. I have to go now so maybe in a couple hours!

1 Like

I hope this video works for you guys but here it is: Tomroblox54321’s Planetary Orbit Module. - YouTube

2 Likes

this is really cool script it would be cooler if it had things like eccentricity to make the orbits much cooler

2 Likes

you can use different Radius for X and Y, maybe like multiply one of them by some value, and the orbit won’t be circular anymore!

But it should be noted, that the planet will be faster in the scaled side

2 Likes

well i wanted something more like the red lines…
image

2 Likes

check the True Anomaly btw

3 Likes

I see. Since the module use the pivot point, you can achieve that easily by changing the position of the pivot of the planet!
But I agree that it would be much cooler to have such crazy features, I’ll try to get my hands dirty when I have enough time.
Otherwise thanks for the great ideas!

1 Like

Daamn, that’s siick, I love desmos, Thanks for the great resource!

1 Like

well yeah i found that from another topic of orbital mechanics where a guy simulated kelper orbital mechanics

3 Likes