Advertisement
1m1m0
Jun 16th, 2024
11
0
Never
This is comment for paste Blackhole v5.0 Prototype
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- [ Blackhole 5.1 Source Code Prototype ] --
  2. -- Integrated smoother gravitational forces for stable simulations.
  3. -- For archived versions, visit my pastebin: https://pastebin.com/u/1m1m0
  4.  
  5. game.Workspace.Gravity = 0 -- This script works best in zero gravity environments! (Optional)
  6. local hole = script.Parent
  7. local gravitationalConstant = 1000 -- Adjust this value to control the strength of the attraction [1000 is default for a black hole]
  8. local updateInterval = 0 -- Time in seconds between updates while computing (Higher = +Accuracy -Performance, Lower = -Accuracy +Performance)
  9. local damping = 0.7 -- Adjust this value to control the rate of force application [1 is no damping, 0.7 is a suggested starting point]
  10. local rangeFactor = 500 -- Maximum range for objects to be effected [500 studs is default]
  11. local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes. (Appearing to fade out of reality)
  12. local dematerializeDuration = 0.01 -- How long (seconds) the fading will last (In seconds) on each transparency increment
  13. local sizeProportion = 50 -- Smaller = faster growth for each absorption
  14. local rangeProportion = 125 -- Bigger = faster range growth
  15. local partColor = BrickColor.new(0) -- Color it changes into before getting deleted. (White is default)
  16. local partMaterialTransform = Enum.Material.Neon -- Material it changes into before getting deleted. (Neon is default)
  17. local absorption = true -- Absorb objects that touch the blackhole
  18. local growth = true -- Allow the blackhole to grow by absorption
  19. local killPlayers = true -- Kill players that touch the blackhole
  20. local collision = false -- Make objects pass through eachother while being absorbed
  21. local fixedPosition = false -- Anchor objects while being absorbed (Better FPS)
  22.  
  23. -- gravitational constants of half or a third of 1000 is perfect for gentle simulations.
  24.  
  25. -- GRAVITATIONAL FORCES --
  26.  
  27. local lastUpdateTime = 0
  28.  
  29. local function ApplyGravity(object)
  30.  
  31.     -- Delay to pause calculations for better FPS
  32.     local currentTime = tick()
  33.     if currentTime - lastUpdateTime < updateInterval then return end
  34.     lastUpdateTime = currentTime
  35.  
  36.     -- Main bulk of gravitational forces
  37.     local direction = hole.Position - object.Position
  38.     local distance = direction.Magnitude
  39.     -- ---Dont touch, this formula has been tweaked for exact range of effectiveness!--- --
  40.     local distanceSquared = (distance/((rangeFactor/100) + ((rangeFactor/100)*(1/64)))) ^ 2
  41.     -- --------------------------------------------------------------------------------- --
  42.     local magnitude = gravitationalConstant / distanceSquared
  43.     local force = direction.Unit * magnitude * object:GetMass()
  44.  
  45.     local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
  46.     if not bodyForce then
  47.         bodyForce = Instance.new("BodyForce")
  48.         bodyForce.Name = "BlackHoleBodyForce"
  49.         bodyForce.Force = Vector3.new(0, 0, 0)
  50.         bodyForce.Parent = object
  51.     end
  52.  
  53.     -- Apply damping to the force to prevent instability
  54.     bodyForce.Force = (bodyForce.Force + force) * damping
  55. end
  56.  
  57. -- MAIN GRAVITATIONAL FORCE COMPUTER (Applies gravity to anything) --
  58.  
  59. local function CheckAndApplyGravity(obj)
  60.     -- Check if the object is a descendant of a BasePart (including all physical objects)
  61.     if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then
  62.         return
  63.     end
  64.  
  65.     -- Exclude the black hole itself and players from gravitational pull
  66.     if obj == hole or obj.Parent:IsA("Player") then -- Remove obj.Parent:IsA("Player") if you like
  67.         return
  68.     end
  69.  
  70.     -- Exclude anchored objects to maximize performance
  71.     if obj.Anchored then
  72.         return
  73.     end
  74.  
  75.     ApplyGravity(obj)
  76. end
  77.  
  78. game:GetService("RunService").Heartbeat:Connect(function()
  79.     for _, object in pairs(game.Workspace:GetDescendants()) do
  80.         CheckAndApplyGravity(object)
  81.     end
  82. end)
  83.  
  84. -- DAMAGE/KILLER (Kills players when they touch it) --
  85.  
  86. function onTouch(part)
  87.     local humanoid = part.Parent:FindFirstChild("Humanoid")
  88.     if humanoid then
  89.         humanoid.Health = 0
  90.     end
  91. end
  92.  
  93. if killPlayers then
  94.     hole.Touched:Connect(onTouch)
  95. end
  96.  
  97. -- DEMATERIALIZER (Deletes ANY object that touches it) --
  98.  
  99. function onTouched(part)
  100.  
  101.     if part.Anchored then -- Prevent anchored objects from being absorbed
  102.         return
  103.     end
  104.  
  105.     -- Calculate average mean size of objects
  106.     local function CalculateAverageSize(part)
  107.         local size = part.Size
  108.         local averageSize = (size.X + size.Y + size.Z) / 3
  109.         return averageSize
  110.     end
  111.  
  112.     local objectAverageSize = CalculateAverageSize(part)
  113.     local blackHoleSize = hole.Size.X
  114.  
  115.     -- Calculate the new size increment based on the object's average size
  116.     local sizeIncrement = (objectAverageSize / (blackHoleSize * sizeProportion))
  117.  
  118.     part.BrickColor = partColor
  119.     part.Material = partMaterialTransform
  120.     part.CanCollide = collision
  121.     part.Anchored = fixedPosition
  122.  
  123.     for _, transparency in ipairs(transparencySteps) do
  124.         part.Transparency = transparency
  125.         wait(dematerializeDuration)
  126.     end
  127.  
  128.     part:Destroy() -- Delete part after completing transparencySteps
  129.  
  130.     if growth then
  131.         -- Adjust the black hole's size based on the new size increment
  132.         hole.Size = hole.Size + Vector3.new(sizeIncrement, sizeIncrement, sizeIncrement)
  133.         rangeFactor = rangeFactor + sizeIncrement * rangeProportion
  134.     end
  135. end
  136.  
  137. if absorption then
  138.     local connection = hole.Touched:Connect(onTouched)
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement