I’ve done the formula correctly yet the LinearVelocity objects have no speed, although they do point at the other planet.
local a = workspace.part1
local b = workspace.part2
local runservice = game:GetService('RunService')
local scale = 1 * (10 ^ 15)
local basedensity = 5560
function gSpeed(mass_a, mass_b, distance)
local G = 6.67408e-11
local force = (G * mass_a * mass_b) / (distance^2)
return force/mass_a
end
function sphere_volume(diameter)
local radius = diameter/2
local volume = (4/3) * math.pi * (radius^3)
return volume
end
while task.wait(0.1) do
local distance = (a.Position-b.Position).Magnitude * scale
local massA = sphere_volume(a.Size.Y) * basedensity * scale
local massB = sphere_volume(b.Size.Y) * basedensity * scale
a.Attachment.relative.VectorVelocity = (b.Position-a.Position).Unit * gSpeed(massA,massB,distance)
b.Attachment.relative.VectorVelocity = (a.Position-b.Position).Unit * gSpeed(massB,massA,distance)
end