this is really cool script it would be cooler if it had things like eccentricity to make the orbits much cooler
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
well i wanted something more like the red lines…
check the True Anomaly btw
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!
Daamn, that’s siick, I love desmos, Thanks for the great resource!
well yeah i found that from another topic of orbital mechanics where a guy simulated kelper orbital mechanics
Thank you soo much! I’m studying physics in university so this will be really helpful for me!
i messed around and got somewhat close enough Eccentricity
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, Eccentricity : number)
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+Eccentricity/2)*CosineMath(Angle)
local y = Radius*SineMath(Angle)
local z = 0
local offset = CFrame.new(Eccentricity,0,0)
PlanetOrbiting:PivotTo((PlanetGettingOrbited.CFrame*offset)*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 code
local Orbit = require(script.OrbitModule)
Orbit(workspace.Part,workspace.Part2,5,15)
I’m so glad and happy people are enjoying the module. It’s also really good for customizing!
Thanks for teaching me a couple more new things for this module. Like how in when you are returning the function you put :PVInstance or :number. I’m a generally new coder so it’s always great to learn. Also thanks @Creeperman16487 for teaching me about eccentricity!
Tomroblox54321’s Planetary Orbit Module V2
In this new update for the module I upgraded the module to be able to disconnect and not use variables when calling the module to run. Codes Otaku or aka @IlyasTawawe improved the module for me so all credit to him!
Hope you enjoy the small improvement!
Hey there! I’m the guy who did the Orbital Mechanics in Roblox devlogs.
Did you know that OrbitLib as seen in that post is now OPEN SOURCE?
I released it quietly and didn’t make an announcement for it because school got in the way. But it should do everything you need it to do. It supports elliptical and hyperbolic orbits (basically 100% of all orbits) and is fairly optimized at what it does.
If you want a demo for what it can accomplish, you can find a version ported to TypeScript and WebGL here:
Just a heads up, the ECI (Earth-centered Inertial) coordinate system uses a different handedness than Roblox’s coordinate system. You’ll have to transform between them for the orbits to display properly.
Otherwise, enjoy!
Ooh. That’s really cool thanks for the cool system and thanks for contribution to the post.
@daftcube This is such an amazing module. It’s clear that you put so much effort into this amazing project. Since I’m a new Coder would you please show me how to use this module for parts.
Thanks!
How would I implement this in-studio because there isn’t really a guide to setup
Really interesting, am surely gonna look into it!
Features in my Advanced Tomroblox54321’s Planetary Orbit Module will be elliptical orbits and eccentric orbits
Tomroblox54321’s Advanced Planetary Orbit Module Is Out!
This is a very advanced module with circular orbits, eccentric orbits , elliptical orbits and more!
Get it here now! : https://www.roblox.com/library/9058460048/Tomroblox54321s-Advanced-Planetary-Orbit-Module
Could you make a video tutorial or at the very least publish an open source example place? I’m kinda stumped. EDIT: nvm got it working