Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to create custom gravity?

Asked by 4 years ago

I've created an orbital gravity script that is supposed to drag all objects in the 'Objects' folder to the biggest object. But my script only works when there is only one object to pull. Thank you!

local objects = workspace.Objects

while wait() do
    local G =  6.67430 * 10 ^ -11
    for x, object in pairs(objects:GetChildren()) do
        for y, otherObject in pairs(objects:GetChildren()) do
            if otherObject ~= object then
                r = otherObject.CFrame.p - object.CFrame.p
                F = G * object:GetMass() * otherObject:GetMass() / r.Magnitude  ^ 2
                object.BodyForce.Force = F * r.Unit
            end
        end
    end

0
Isn’t there supposed to be an end to close the while wait loop? FrontsoldierYT 129 — 4y

Answer this question