Been stuck for hours on fixing my orbiting system

Mathematically, and empirically increasing distance between objects will increase the stability of the system. Slowing down time is no different from manually resetting the positions of the bodies in the system to re-stabilize it. Decreasing mass is just plain stupid. Gravitational systems thrive on inequality of mass, and centrality. Decreasing gravity is inefficient, because in the hypothetical stance that you have multiple systems working, those other systems will fail. Increase distance only. You should never FIDDLE with the gravity. Keep it at a reasonable amount, but change the distance, predominantly, or the mass.

Line forces are something I would use, only if there’s an option to set RelativeTo to the world instead of using both attachments. The reason why I don’t want to use lineforces is because I want the planet to be affected more than one body like planets or maybe even asteroids, and be affected by it’s surroundings instead of only targeting the star.

Perhaps I’m going to use linearvelocity again since I start to realize changing positions every loop seems more inefficient and causes the program to lag even further.

What’s the solution to this problem?

Wait… Actually this solves everything, so you are right! So with this idea, it managed to move exactly the way I wanted.

Hmm. But I have multiple questions regarding it.

  • If I want to make a planet eject out of the star system, how can I do so?

  • How do I set the orbiting time to become real time? (like very. slow)

  • Is there a way to find the escape region of the planet or the star?
    I want to know whether the player is fully in space, or if the player is in the star/planet’s atmosphere

Video result!!!


That doesn’t look quite right to me.

I think this line is supposed to be the square of distance, not the square root of distance.


Just keep adding velocity. You can add velocity in the current_velocity.Unit direction and it should work well enough, but the more computationally expensive ‘proper’ direction is tangential to the planet like so:

local to_planet = (planet_pos - this_pos).Unit
local tangent = to_planet:Cross(this_velocity).Unit:Cross(to_planet)

There’s a good chance that ‘tangent’ needs to be negative after this but it’s too early in the morning for that kind of thing.

How much force to add though?
idk
Congratulations, you can say that you’ve done calculus now. Even though it was for a simulation, this little loop you made is used as an integration to solve calculus problems, such as orbital mechanics. If you want to know if the force was enough to escape the system, you need to solve the problem with calculus. You could run a simulation like the one you just made. Don’t use any waits or events for it, just calculate it all with a while loop until the velocity starts increasing again (going towards the planet) or you reach the end of the sphere of influence.
I know there’s going to be a better way, and possibly even a way to determine the exact force required (rather than just checking if a force is enough) but I have no experience with calculus beyond what we’ve already done in this thread.

There are several ways to do this. You could decrease the velocity that applied to the positions. (don’t modify the velocity stored in a table or attribute) That way you still get the same motion but less of it.

planet.Position += velocity * 0.05

You could also increase the distance between objects. If that’s inconvenient from a viewing or editing perspective, you can decrease the mass or the gravitational constant. If you change gravity or mass, you will also need to slow down the planets or they’ll just fly off into the void. But slowing them down is the goal here, yeah?

That’s a little more complicated. Most video games (i.e. Kerbal) use a fixed distance and only allow one source of gravity at a time. That’s the easy way. In the first video it looks like a binary star system, so I assume you’re calculating every source of gravity. If that’s the case, you could check if the force of gravity of the planet you’re near is greater than the sum of all other gravity wells. This still has issues because real life doesn’t true spheres of influence. In real life, there is only ‘orbiting’ and ‘escaping’, and we need to go back to calculus to figure out which one we’re doing.

Since spheres of influence don’t exist, in that regard this problem is up to you. You’re making distinctions where distinctions don’t exist and so you can handle it however you see fit. Unless you’re using a fixed distance, it’s going to require a bit of calculation. This is getting computationally expensive for a playable game in Lua, but if you’re just making a solar system simulator I’m sure you’ll be fine.

Atmosphere is different of course, and the outer edge is almost always treated as a fixed distance. You could try to create an atmospheric pressure gradient if you wanted, but I don’t personally know the equations for how it scales.

1 Like

You should research it yourself. Everything is better understood when you have pondered about it on your own :).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.