Solar System using only roblox physics

  1. What I want to achieve:
    Hello, I’m trying to make an orbital system where planets orbit around a sun at a random velocity/speed. To be very clear: I am not using CFrame, This is based on pure Roblox physics using a LineForce.

  2. The issue:
    I cannot seem to find the right formula to use so that, regardless the size of the planet, the magnitude will always be the right amount for a stable orbit.

  3. What solutions have you tried so far?
    I have tried googling up formulas for stable orbits using Mass,Velocity and Magnitude, but all I can find are very complicated formulas that use symbols that I am not familiar with(I’m 14 years old so I am not an expert when it comes to math in any way, I just wanna make cool space stuff :sweat_smile:). I’ve also searched around on the forums, but I can’t find anyone who is specifically trying to achieve what I am.

Here’s the code:

--//Objects
local Planet = script.Parent
local Sun = script.Parent.Parent

--//Attachments + lineforce
local LineForce = Instance.new("LineForce")
local Attatchment0 = Instance.new("Attachment")
local Attatchment1 = Instance.new("Attachment")

--//Setting up the attachments and lineforce
Attatchment0.Parent = Planet --// Putting attachment0 in the planet
Attatchment0.Visible = true --// Making Visible
Attatchment1.Parent = Sun --// Putting attachment1 in the sun
Attatchment1.Visible = true --// Making Visible
LineForce.Parent = Planet --// Putting the lineforce in the planet
LineForce.Attachment0 = Attatchment0 --// Aplying attachment0 to the lineforce
LineForce.Attachment1 = Attatchment1 --// Aplying attachment1 to the lineforce
--//Ticking all the boxes in the lineforce
LineForce.ApplyAtCenterOfMass = true
LineForce.ReactionForceEnabled = true
LineForce.InverseSquareLaw = false
LineForce.Visible = true

local RanVel = math.random(100,500) --// Choosing a random velocity(the speed at which I want the planet to orbit)
Planet.Velocity = Vector3.new(0,0,RanVel) --// Aplying the velocity to the planet
LineForce.Magnitude = --//??? this is the part where im stuck, I don't know the formula :( Is there even one?

Quick sidenote: This is my first topic on the DevForum. Feedback is free to give and recieve so I’ll take any! For the rest thank you for reading! :slight_smile:

EDIT: If you’re reading this edit then don’t waste your time trying to help me with this. I’ve already given up. If you wanna know why just read all the replies under this topic. It was lovely to see how nice people are here. I just don’t want to tell everyone the dissapointing news that i gave up after they spent their time trying to solve my problem. I’ll probably take on this another time when i’m better at Lua.

7 Likes

There is a video about this on youtube.

4 Likes

I have already watched it. In the video he never mentions a formula, although he does mention that it’s possible to do with scripts. which is what motivated me to try this. I very much appreciate the help though!

Why don’t use just try the magnitude that he did

200000 or 20000

alright. Here is my take on this. You better sit down and listen to this properly, as this is gonna sound like rocket science lol.

Magnitude is also known as F, or Force… which is basically the Force of Gravity. Take a look at this equation i just made:

image

G should stand for the Direction of force in a straight line. Keep this number as

6.67 × 10^-11 as that is what it is in real life (without the kg^-2 and m^2)

Next, take the two masses of both objects, M being the larger mass and m being the smaller mass. For instance, The Earth’s mass would be M, while the moon’s mass should be m. To determine this, there should be a property where you can get the mass of a part. It should be read-only and greyed out.

r^2 is the distance between the centers of the objects. If you center your LineForce in the middle of the planets (like in the video above), you should be able to determine the distance by the properties tab for the LineForce. There should be a property that you cannot edit called TotalLength or something like that. It is greyed out.

Since we are leaving out m^2 of G, we need to multiply that in at the end.

So all of this is to determine the Magnitude only. Lets say the Earth mass is 5, and the moon mass is .5. The distance between the centers of the objects will be 10 studs. Because of this:

image

1 stud is equal to 5 cm. so we need to convert that into m. This is what it would equal:

500cm = 5m

Now lets put it into a script.

LineForce.Magnitude = (((6.67*10^-11*5^2)(5)(.5))/(10^2))

This is the answer:

4.16875*10^-11 or 0.0000000000416875

This is not right. Remember that kg^-2 ? we need to raise everything by -2. This is what we get:

5.7542443171*10^20 or 575424431710000000000

we now need to divide it by 10000000000 because a stud is 10000000000 of a kg^2.
The answer:

5.7542443171*10^10 or 57542443171

So this is the full script:

LineForce.Magnitude = (((((6.67*10^-11*5^2)(5)(.5))/(10^2))^-2)/(10000000000))

Here is the script without values:

LineForce.Magnitude = (((((6.67*10^-11*5^2)(M)(m))/(r^2))^-2)/(10000000000))

anyways, i hope you had fun reading this!

read this: Refer your moon as a satellite: Index of /~pfrancis/roleplay/MysteryPlanet/Orbits this is some extremely helpful info :slight_smile:

Example

Consider a tower-block 1000 km high, protruding above the Earth’s atmosphere. Imagine that you are dropping something off the top of this tower. If you just drop it (ignoring the rotation of the Earth), it will fall straight down, burning up in the atmosphere near the base of the tower.

But now, give it a sideways push as you drop it. As it falls, it will continue to move sideways, until it burns up. The harder you push it, the further away from the base of the tower it will land.

If you push it hard enough, it will miss the Earth altogether – by the time it’s fallen 1000 km, it will have moved so far sideways that the Earth is no longer below it. If you’re clever, you can get it moving in a circle around the Earth – perpetually falling but never hitting the bottom.

psst. I am young like you too lol. I have been studying physics for about 2 years. If something is off, then it might be the conversions with Roblox to real life distance and weight.

10 Likes

Thank you so much! I saw the formula you talked about on a wikipedia page and I didn’t understand a single bit. Thanks to you I now understand how it works! After I read through this a couple more times I’ll try implementing it in my game!

1 Like

This wouldn’t work because if you raise the magnitude by a lot, bigger planets might stay in orbit while smaller planets with lesser mass will be pulled towards the sun in a near straight line.

Hi. I’m back agian. I’m in roblox studio and I’ve implemented the formula and aplied all of the values:

LineForce.Magnitude = (((((6.67*10^-11*5^2)*(Sun.Mass)*(Planet.Mass)/(((Sun.Position - Planet.Position).Magnitude)^2))^-2)/(10000000000)))

However, I’m still left with some questions about what you did with this formula. Here’s the formula with all my questions adressed:

LineForce.Magnitude = (((((6.67*10^-11*5^2<--- Where does this 5^2 come from?)*(Sun.Mass)*(Planet.Mass)/(((Sun.Position - Planet.Position).Magnitude)^2<--- Am I suppose to keep this ^2?))^-2)/(10000000000)))

I’ve tried changing small things to the formula, such as removing the 5^2 and/or the ^2. Even when not changing anything and just filling in the M,m and r, the planets wont stay in a stable orbit. Could you maybe tell me what I’m doing wrong here? Also I forgot to mention that there is no such property in a LineForce that indicates what the distance is between the two parts. So as you probably noticed I manually calculated the distance of the two parts.

2 Likes

My bad. Remove the *5^2. I guess I wrote that wrong :confused:

So for the Distance, you are doing it right, but you need to multiply the Magnitude by 20 before squaring it. You need to do this because 1 stud is 5 cm, and the distance is suppost to be measured in meters.

Here is the line:

LineForce.Magnitude = (((6.67*10^-11)*(((((Sun.Mass*Planet.Mass)/(Sun.Position - Planet.Position).Magnitude)*20)^2)^-2))/(1E10^10))

I changed the 10000000000 to scientific notation to keep it from looking sloppy. There should be no difference. If there is, try changing the 10^10 to 10^9 at the end.

EDIT: I fixed the parentheses lol

1 Like

There is one problem though. Running this equation multiple times is extremely inefficient.

I know you said you did not want to use CFrames, but if worst comes to worst, let this be there for you:

Orbital.rbxl (14.3 KB)

credits to @PlaceRebuilder.

1 Like

Thank you so much. You’ve been and a massive help trough all of this and I could not have done it without you.

Aha, this really sucks after all the effort that was put into this… turns out that the number you get from this formula is so big, Roblox automaticly sets it to zero when you try to apply it to the magnitude… I was confused at first why it didn’t set the magnitude, so I printed out the result of the formula, here is the avarge number you would get from it:
5.0737893413545e-111 ( I say avarege since not all planets have the same mass. sometimes the number even goes up to 9.3567528502507e-108 )

I copied the printed number into the magnitude to see if it was just a bug or if the number was actually too big, and i got the bad result… (It’s too big.)

Well, it is what it is :sweat_smile:. Still I wanna thank you for your help. We can’t do anything about the limits of Roblox Studio.

Unfortunately the easiest way it seems to do this in Roblox is to scale everything down.

What I was able to do (most recent + accurate version):

A 2D (but slightly older) project that had orbiting planets as well:

1 Like

“The Limits of roblox studio” Are you serious? You didnt even attempt to increase the delta rate? Even didnt consider to use billboard guis?

1 Like

yeah i just realized this. I was making my own test and I realized that it was being set to zero. This makes sense because magnitude of real life planets are huge numbers sooo. yeah. The number you provided is actually a negative number. You can try multiplying the entire equation by -1… Here is that number:

image

That is not a high value if multiplied by -1.

So maybe try this line:

LineForce.Magnitude = ((((6.67*10^-11)*(((((Sun.Mass*Planet.Mass)/(Sun.Position - Planet.Position).Magnitude)*20)^2)^-2))/(1E10^10)))*-1

also, your velocity is just wrong in general, I am now realizing. Try doing this line:

local RanVel = math.sqrt((6.67*10^-11)(Sun.Mass)/(Sun.Position - Planet.Position).Magnitude)

Again, I know you don’t want to use CFrames, but If you have too, I uploaded a place download that automates everything. It should just be better in general.

@CoderHusk, give him a break man. It is obvious that he is bummed about this. Sometimes, it’s okay to give up on something.

1 Like

What do you mean with delta rate? Also, how are billboard gui’s going to help may I ask?

1 Like
  1. Billboard guis give the illusion of huge
  2. delta refresh rate refers to how fast are you updating the simulation
2 Likes

you might have a problem with your velocity too. try the equation i edited above.

1 Like

I aplied it:

local Vel = math.sqrt((6.67*10^-11)*(Sun.Mass)/(Sun.Position - Planet.Position).Magnitude)

Planet.Velocity = Vector3.new(0,0,Vel) --// Aplying the velocity to the planet

But now the planets dont move at all. Also the magnitude is still zero. As you said, it’s fine to give up on something for once. I might retry this agian later when i’m hopefully much more prepared and have more expierence with Lua. Agian, I can’t thank you enough for helping me out.

Yes, I did use billboard gui’s even before scaling down everything. The size of a planet now is at maximum 1 stud and minimum 0.1 stud(they used to be between 100 and 200 studs in diameter). Even then, the numbers were too big.