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

Why does my custom orbital gravity script not work?

Asked by 4 years ago
Edited 4 years ago

Why does my orbital gravity script only pull one object at a time?

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
end

Answer this question