How to make any Instance orbit around other Instances

So I’m trying to figure out how to make any instance for example part, or a ui button circle around another. Does anyone know how I can do this, or have any tutorials I can watch to learn how this works?

I found this script somewhere in the DevForum probably a few months ago so this should help.

local center = -- path to part
local planet = -- path for orbiting the center/part

local ORBIT_TIME = 2
local RADIUS = 10 -- how far the orbit is
local ECLIPSE = 1 -- ranges from 0 to 1, perfect circle if 1
local ROTATION = CFrame.Angles(0,0,0) --rotate which direction to rotate around


local sin, cos = math.sin, math.cos
local ROTSPEED = math.pi*2/ORBIT_TIME
ECLIPSE = ECLIPSE * RADIUS
local runservice = game:GetService('RunService')

-- There are many ways to run this loop, you could do while true do if you want, if so use this: rot = rot + wait() * ROTSPEED 
local rot = 0
game:GetService('RunService').Stepped:connect(function(t, dt)
	rot = rot + dt * ROTSPEED
	planet.CFrame = ROTATION * CFrame.new(sin(rot)*ECLIPSE, 0, cos(rot)*RADIUS) + center.Position
end)
3 Likes

You can use a constraint though…

1 Like

Now I know you can just use it by constraints, what constraint?

I meant… LineForces. Simulating Planetary Gravity using Line Forces! - Roblox Studio - YouTube
It’s way easier than using a script.

2 Likes

@devwingfr Nice to know you can use constraints, the main reason I made this thread though was because I wanted to know how to do this using scripts because some stuff for example camera manipulation, and other stuff like UI doesn’t allow you to use constraints.

Didn’t know that, I guess @Crictoli solved the problem.

You could try my module. It is a simple and easy to use free module that contains circular orbits, eccentric orbits and elliptical orbits currently!

Get it here now : Tomroblox54321’s Advanced Planetary Orbit Module!