Advertisement
1m1m0

Celestial Body (Non-BH)

Jan 2nd, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | Source Code | 0 0
  1. local celestial = script.Parent -- Change this to reference your black hole part
  2. local gravitationalConstant = 50 -- Adjust this value to control the strength of the attraction
  3.  
  4. local function ApplyGravity(object)
  5.     local direction = celestial.Position - object.Position
  6.  
  7.     local force = direction.Unit * gravitationalConstant
  8.  
  9.     local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
  10.     if not bodyForce then
  11.         bodyForce = Instance.new("BodyForce")
  12.         bodyForce.Name = "BlackHoleBodyForce"
  13.         bodyForce.Force = force
  14.         bodyForce.Parent = object
  15.     else
  16.         bodyForce.Force = force
  17.     end
  18. end
  19.  
  20. game:GetService("RunService").Heartbeat:Connect(function()
  21.     for _, object in pairs(game.Workspace:GetChildren()) do
  22.         if object:IsA("BasePart") and object ~= celestial then
  23.             ApplyGravity(object)
  24.         end
  25.     end
  26. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement