Advertisement
1m1m0
Jun 17th, 2024
20
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.0 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. -- No, i did not get a bachelor of physics just for this
  6.  
  7. game.Workspace.Gravity = 0 -- This script works best in zero gravity environments! (Optional)
  8. local hole = script.Parent
  9. local gravitationalConstant = 1000 -- Adjust this value to control the strength of the attraction [1000 is default for a black hole]
  10. local updateInterval = 0 -- Time in seconds between updates while computing (Higher = +Accuracy -Performance, Lower = -Accuracy +Performance)
  11. 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]
  12. local rangeFactor = 500 -- Maximum range for objects to be effected [500 studs is default]
  13. local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes. (Appearing to fade out of reality)
  14. local dematerializeDuration = 0.01 -- How long (seconds) the fading will last (In seconds) on each transparency increment
  15. local sizeProportion = 35 -- Smaller = faster growth for each absorption
  16. local rangeProportion = 125 -- Bigger = faster range growth
  17. local partColor = BrickColor.new(0) -- Color it changes into before getting deleted. (White is default)
  18. local partMaterialTransform = Enum.Material.Neon -- Material it changes into before getting deleted. (Neon is default)
  19. local absorption = false -- Absorb objects that touch the blackhole
  20. local growth = true -- Allow the blackhole to grow by absorption
  21. local killPlayers = true -- Kill players that touch the blackhole
  22. local collision = false -- Make objects pass through eachother while being absorbed
  23. local fixedPosition = false -- Anchor objects while being absorbed (Better FPS)
  24. local forceStabilizer = false -- Toggle to decelerate objects when entering event horizon from infinity
  25.  
  26. -- GRAVITATIONAL FORCES --
  27.  
  28. local lastUpdateTime = 0
  29.  
  30. --[
  31. local function ApplyGravity(object)
  32.  
  33.     local direction = hole.Position - object.Position
  34.     local distance = direction.Magnitude
  35.     local blackHoleRadius = hole.Size.X / 2
  36.  
  37.     -- Prevents objects from accelerating too fast
  38.     if distance < blackHoleRadius and forceStabilizer then
  39.         direction = -direction
  40.     elseif distance < blackHoleRadius then
  41.         return
  42.     end
  43.  
  44.     -- Set up main physics calculations
  45.     local distanceSquared = (distance/((rangeFactor/100) + ((rangeFactor/100)*(1/64)))) ^ 2 -- Dont touch lol
  46.     local magnitude = gravitationalConstant / distanceSquared
  47.     local force = direction.Unit * magnitude * object:GetMass()
  48.  
  49.     local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
  50.     if not bodyForce then
  51.         bodyForce = Instance.new("BodyForce")
  52.         bodyForce.Name = "BlackHoleBodyForce"
  53.         bodyForce.Force = Vector3.new(0, 0, 0)
  54.         bodyForce.Parent = object
  55.     end
  56.  
  57.     -- Apply the force, reversed if within the black hole's volume
  58.     bodyForce.Force = (bodyForce.Force + force) * damping
  59. end
  60.  
  61. -- MAIN GRAVITATIONAL FORCE COMPUTER (Applies gravity to anything) --
  62.  
  63. local function CheckAndApplyGravity(obj)
  64.     -- Check if the object is a descendant of a BasePart (including all physical objects)
  65.     if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then
  66.         return
  67.     end
  68.  
  69.     -- Exclude the black hole itself and players from gravitational pull
  70.     if obj == hole or obj.Parent:IsA("Player") then -- Remove obj.Parent:IsA("Player") if you like
  71.         return
  72.     end
  73.  
  74.     -- Exclude anchored objects to maximize performance
  75.     if obj.Anchored then
  76.         return
  77.     end
  78.  
  79.     ApplyGravity(obj)
  80. end
  81.  
  82. game:GetService("RunService").Heartbeat:Connect(function()
  83.     for _, object in pairs(game.Workspace:GetDescendants()) do
  84.         CheckAndApplyGravity(object)
  85.     end
  86. end)
  87.  
  88. -- DAMAGE/KILLER (Kills players when they touch it) --
  89.  
  90. function onTouch(part)
  91.     local humanoid = part.Parent:FindFirstChild("Humanoid")
  92.     if humanoid then
  93.         humanoid.Health = 0
  94.     end
  95. end
  96.  
  97. if killPlayers then
  98.     hole.Touched:Connect(onTouch)
  99. end
  100.  
  101. -- DEMATERIALIZER (Deletes ANY object that touches it) --
  102.  
  103. function onTouched(part)
  104.  
  105.     if part.Anchored then -- Prevent anchored objects from being absorbed
  106.         return
  107.     end
  108.    
  109.     local initialBlackHoleSize = hole.Size.X
  110.     local initialRangeFactor = rangeFactor
  111.  
  112.     -- Calculate average mean size of objects
  113.     local function CalculateAverageSize(part)
  114.         local size = part.Size
  115.         local averageSize = (size.X + size.Y + size.Z) / 3
  116.         return averageSize
  117.     end
  118.  
  119.     local objectAverageSize = CalculateAverageSize(part)
  120.     local blackHoleSize = hole.Size.X
  121.  
  122.     -- Calculate the new size increment based on the object's average size
  123.     local sizeIncrement = (objectAverageSize / (blackHoleSize * sizeProportion))
  124.  
  125.     part.BrickColor = partColor
  126.     part.Material = partMaterialTransform
  127.     part.CanCollide = collision
  128.     part.Anchored = fixedPosition
  129.  
  130.     for _, transparency in ipairs(transparencySteps) do
  131.         part.Transparency = transparency
  132.         wait(dematerializeDuration)
  133.     end
  134.  
  135.     part:Destroy() -- Delete part after completing transparencySteps
  136.  
  137.     if growth then
  138.         -- Adjust blackhole size
  139.         hole.Size = hole.Size + Vector3.new(sizeIncrement, sizeIncrement, sizeIncrement)
  140.  
  141.         -- Growth ratio
  142.         local growthRatio = hole.Size.X / initialBlackHoleSize
  143.  
  144.         -- Apply growth ratio
  145.         rangeFactor = initialRangeFactor * growthRatio
  146.     end
  147. end
  148.  
  149. if absorption then
  150.     local connection = hole.Touched:Connect(onTouched)
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement