Universe sandbox 2 collision system

Hi, I am recently making a gravitation simulation on my PC.

I was wondering how Universe Sandbox 2 did it.

If you don’t know what Universe Sandbox is, check out this gameplay Video.

Should I put the script into celestial body or ServerScriptService?
And I am having calculation problem about the size change.

1 Like

There are various issues with your question, as we have no point of reference about your issue.

BUT I was a beta tester of US2 and have pretty extensive knowledge about the workings of the game, so I can help you a bit with the gist of how they did it.

They use Newton’s Law of Universal Gravitation to simulate gravity. They calculate the radius of objects based on the mass and density following the object’s composition. Eg if an object is 100kg (mass), and is made out of pure iron (density of 7.874 g/cm³) then following a spherical volume equation the radius would be calculated as such:

Volume = 100kg / 7.875g (per cm³) = ~12700.0254 cm³
Radius = (3 * (12700.0254 / (4 * PI)))^(1/3) = ~14.47cm
Diameter (size) = 14.37 * 2 = 28.94cm
7 Likes

That was the very first question I ever asked in this forum. Asked, here’s the to link it, I think it will help you.

I’m talking about collision, not gravity.

If the magnitude between the two sphere’s center points (c0 and c1) is less than the sum of both radii (r0 and r1) then the spheres have intersected.

local function AreSpheresColliding(sphere0, sphere1)
   local magnitude = (sphere0.Position - sphere1.Position).Magnitude

   If magnitude <= (sphere0.Size.X/2) + (sphere1.Size.X/2) then
       return true
   else
       return false
   end
end
2 Likes