Most efficient way to simulate gravitational attraction in realtime?

I’m trying to make a planet framework for fun, I can probably work out the rest of the stuff that I want to implement, the biggest problem so far is, what is the most efficient way to have all objects within a certain radius be attracted to a sphere no matter what angle you’re coming in from?

My original idea was to use constraints but that would get real buggy real fast so no to that.

The thing that I’m thinking of using right now is BodyMovers but I would like input from someone more skilled and proficient at coding than I am if there is another solution.

(If you could throw in how to keep the character pointing up like this

mspaint%20example%20lolol

then that would be very much appreciated though not completely necessary)

3 Likes

I have thought of making a planet the last month, but never started. I’m not sure whether this will work or not, but my plan was to use velocity and bodygyro. The velocity of the humanoidrootpart will make sure the character is attracted to a point, then I’ll tween the part’s velocity so it goes faster every second.

You can detect magnitude (Ex: have a “range”) between the player and the sphere (or whatever object) and change the Humanoid’s CFrame accordingly. This can be done smoothly using TweenService.

You can do this with certain body movers.

Use LineForces with:

Use BodyGyros to rotate the character correctly. This may cause issues with movement or animations, though. I’ve never attempted this myself.

13 Likes

Related, this may be useful to you:

2 Likes

That’s actually quite useful.

Though I don’t like the way it does it (by rotating the entire world along with you), because then you can fall off very easily.

EDIT: Maybe not?

This better be the last edit to this post.

BodyGyros that are in the RootPart are fine, from what I can see, but they won’t override the humanoid’s auto-level, iirc

2 Likes

All right I tried it, it works!

For the most part, the InverseSquareLaw property isn’t working, it just makes the attracted part come to a dead stop (in zero-grav, I have zero-grav on because gravity overpowers the LineForce) with no acceleration whatsoever, even when really close, am I missing something?

Does setting the LineForce.MaxForce of the LineForce to math.huge (for testing purposes; this will need to be reduced) fix the issue?

1 Like

It was already like that when I spawned it in and turned the property on.

In other words, no.