Advertisement
1m1m0

Blackhole v5.0 RESCRIPTED

Mar 16th, 2025 (edited)
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.16 KB | Source Code | 0 0
  1. -- [ Blackhole Alpha Release v5.0 RESCRIPTED ]
  2. -- Integrated constraint-based gravity for even smoother simulations
  3. -- Happy 3rd birthday, Blackhole 1.0! :D
  4.  
  5. local blackHole = script.Parent         -- Reference
  6.  
  7. -------------------------------------------------------
  8. -- | CONTROL PANEL | -- (See Documentation for info) --
  9. -------------------------------------------------------
  10.  
  11. -- {GRAVITY} --                         {G}
  12. local gravity = 100                     -- Base gravitational constant
  13. local alignSpeed = 5                    -- How quickly the AlignPosition responds
  14. local forceCap = 4000                   -- Maximum force (constraint cap) Note that math.huge means infinity (for realistic gravity, higher cap = higher accuracy)
  15. local range = 500                       -- Effective range of gravitational pull
  16. local centerOfMassBased = false         -- Toggle force application at center of mass
  17. local realisticGravity = false          -- Toggle inverse square law (closer objects have greater gravity)
  18. local realGravDamping = 32              -- Factor to control gravity when `realisticGravity` is on (higher = faster)
  19. local microGravity = false              -- Disable workspace gravity
  20. local gravityEngine = "linear1"         -- Choose the gravity engine ("linear1", "linear2", "line", "vector", "align", "bodyvelocity", "bodyforce")
  21. local gravitationMode = "universal"     -- "selective" (only tagged objects) vs "universal" (everything)
  22. local attractionTag = "attractable"     -- Tag required if `gravitationMode` is selective
  23.  
  24. -- {ABSORPTION} --                      {A}
  25. local absorption = true                 -- Absorb objects on contact
  26. local growth = true                     -- Blackhole grows when absorbing objects
  27. local growthDamping = 0.01              -- Damping factor for growth
  28. local fading = true                     -- Fade objects out before absorption
  29. local fadeDuration = 1                  -- Time (in seconds) to fade out
  30. local anchoring = false                 -- Anchor objects when fading
  31. local colorShift = true                 -- Change color of objects as they fade
  32. local color = Color3.fromRGB(255, 0, 0) -- Target color for shifting (red by default)
  33. local rocheFactor = 2                   -- Multiple of blackHole’s size at which non-gravity joints are removed (0 disables)
  34. local merging = true                    -- Allow blackholes to merge
  35.  
  36. -- {SPECIAL EFFECTS} --                 {S}
  37. local lensing = true                    -- Gravitational lensing effect
  38. local lensingFactor = 2.5               -- Multiplier for the lensing effect’s radius
  39. local lensingStrength = 100             -- Strength of lensing effect (don’t set too high)
  40. local cameraDistortion = true           -- Camera FOV distortion when within range
  41. local distortThreshold = 1              -- Percentage of range for FOV distortion threshold
  42. local blackHoleSound = true             -- Toggle blackhole sound
  43. local distortSound = false              -- Toggle pitch distortion when blackholes are near
  44. local toggleEmitters = true             -- Turn VFX emitters on or off
  45.  
  46. -- {DEBUGGING} --
  47. local logging = true                    -- Toggle logging output (note that not all errors are taken into account, just most)
  48. local logSettings = true                -- Log detailed settings
  49.  
  50. ------------------------
  51. -- | CORE MECHANICS | --
  52. ------------------------
  53.  
  54. local camera = workspace.Camera     -- For camera distortion effects
  55. local defaultFOV = camera.FieldOfView
  56.  
  57. -- Track previous size for proportional updates
  58. local previousSize = blackHole.Size.X
  59.  
  60. -- Table to keep track of active constraints and attachments
  61. local activeGravity = {}
  62. local blackHoleAttachment = Instance.new("Attachment")
  63. blackHoleAttachment.Parent = blackHole
  64.  
  65. -- Convert string inputs to lowercase for consistency
  66. gravityEngine = gravityEngine:lower()
  67. gravitationMode = gravitationMode:lower()
  68.  
  69. -- Helper: Clamp distance to a minimum value to avoid division by zero
  70. local function clampDistance(dist)
  71.     local minDist = 1
  72.     return math.max(dist, minDist)
  73. end
  74.  
  75. -- The master formula for modern gravities *insert angel chorus*
  76. local masterFormula = function(object)
  77.     local distance = (blackHole.Position - object.Position).Magnitude
  78.     local effDist = clampDistance(distance)
  79.     if realGravDamping < 0 then
  80.         realGravDamping = 1 -- Prevent division by 0
  81.     end
  82.     -- Compute the gravitational force using Newtonian physics with conversion
  83.     ------------------------------------------------------------------------------------------------------------
  84.     local computedForce = (gravity * blackHole:GetMass() * object:GetMass()) / ((effDist / realGravDamping) ^ 2) -- ONLY APPLIES TO REALISTIC GRAVITY!
  85.     ------------------------------------------------------------------------------------------------------------
  86.     -- Clamp the force to forceCap so that it never exceeds this maximum
  87.     return math.min(computedForce, forceCap)
  88. end
  89.  
  90. -- The legacy master formula for bodyforce and bodyvelocity
  91. local legacyMasterFormula = function(object)
  92.     local direction = blackHole.Position - object.Position
  93.     local dist = clampDistance(direction.Magnitude)
  94.     --------------------------------------------------------------------------
  95.     local forceMag = (gravity * blackHole.Size.X * object.Size.X) / (dist ^ 2)
  96.     --------------------------------------------------------------------------
  97.     -- For BodyVelocity, if the object is too close to the blackHole, we nullify the force.
  98.     if dist < blackHole.Size.X / 2 then
  99.         forceMag = 0
  100.     end
  101.     return {
  102.         distance = dist,
  103.         direction = direction.Unit,
  104.         force = forceMag,
  105.     }
  106. end
  107.  
  108. local whiteHoleMode = false -- secret event hehe
  109. -- doesnt work if you force this to be true haha
  110.  
  111. -- Function to apply gravity to an object using the selected gravity engine
  112. local function ApplyGravity(object)
  113.     if activeGravity[object] then return end
  114.  
  115.     local objectAttachment = Instance.new("Attachment")
  116.     objectAttachment.Parent = object
  117.    
  118.     local distance = (blackHole.Position - object.Position).Magnitude
  119.     local effDist = clampDistance(distance)
  120.  
  121.     if gravityEngine == "linear1" or gravityEngine == "1.1" or gravityEngine == "linear2" or gravityEngine == "1.2" then
  122.         local linearVel = Instance.new("LinearVelocity")
  123.         linearVel.Attachment0 = objectAttachment
  124.         linearVel.RelativeTo = Enum.ActuatorRelativeTo.World
  125.         linearVel.MaxForce = forceCap
  126.  
  127.         -- Whitehole mode oh my goodness gracious
  128.         if gravity < 0 then
  129.             whiteHoleMode = true
  130.         end
  131.  
  132.         if gravityEngine == "linear1" or gravityEngine == "1.1" then
  133.             linearVel.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
  134.             local lineDir = (blackHole.Position - object.Position).Unit
  135.             linearVel.LineDirection = lineDir
  136.             linearVel.LineVelocity = gravity
  137.  
  138.         elseif gravityEngine == "linear2" or gravityEngine == "1.2" then
  139.             linearVel.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
  140.             local dist = (blackHole.Position - object.Position).Unit
  141.             if realisticGravity then
  142.                 linearVel.VectorVelocity = dist * masterFormula(object)
  143.             else
  144.                 local newVelocityMag = (distance > 0) and (gravity / distance) or 0
  145.                 linearVel.VectorVelocity = (blackHole.Position - object.Position).Unit * newVelocityMag * gravity
  146.             end
  147.         end
  148.        
  149.         linearVel.Parent = object
  150.         activeGravity[object] = { constraint = linearVel, attachment = objectAttachment }
  151.  
  152.         -- LineForce-based gravity
  153.     elseif gravityEngine == "line" or gravityEngine == "2" then
  154.         local lineForce = Instance.new("LineForce")
  155.         lineForce.Attachment0 = objectAttachment
  156.         lineForce.Attachment1 = blackHoleAttachment
  157.         lineForce.ApplyAtCenterOfMass = centerOfMassBased
  158.         lineForce.MaxForce = forceCap
  159.  
  160.         if gravity < 0 then
  161.             -- Swap attachments to reverse the force direction
  162.             lineForce.MaxForce = -forceCap
  163.             whiteHoleMode = true
  164.         end
  165.  
  166.         if realisticGravity then
  167.             lineForce.Magnitude = masterFormula(object)
  168.         else
  169.             lineForce.Magnitude = gravity
  170.         end
  171.         lineForce.Parent = object
  172.         activeGravity[object] = { constraint = lineForce, attachment = objectAttachment }
  173.  
  174.         -- VectorForce-based gravity
  175.     elseif gravityEngine == "vector" or gravityEngine == "3" then
  176.         local vectorForce = Instance.new("VectorForce")
  177.         vectorForce.Attachment0 = objectAttachment
  178.         vectorForce.RelativeTo = Enum.ActuatorRelativeTo.Attachment1
  179.  
  180.         -- Whitehole mode
  181.         if gravity < 0 then
  182.             whiteHoleMode = true
  183.         end
  184.        
  185.         if realisticGravity then
  186.             local direction = (blackHole.Position - object.Position).Unit
  187.             vectorForce.Force = direction * masterFormula(object)
  188.         else
  189.             vectorForce.Force = (blackHole.Position - object.Position).Unit * gravity
  190.         end
  191.         vectorForce.ApplyAtCenterOfMass = centerOfMassBased
  192.         vectorForce.Parent = object
  193.         activeGravity[object] = { constraint = vectorForce, attachment = objectAttachment }
  194.  
  195.         -- AlignPosition-based gravity
  196.     elseif gravityEngine == "align" or gravityEngine == "4" then
  197.         local alignPos = Instance.new("AlignPosition")
  198.         alignPos.Attachment0 = objectAttachment
  199.         alignPos.Attachment1 = blackHoleAttachment
  200.         alignPos.MaxForce = forceCap
  201.         alignPos.MaxVelocity = forceCap
  202.         alignPos.Responsiveness = alignSpeed
  203.         alignPos.ApplyAtCenterOfMass = centerOfMassBased
  204.         alignPos.Parent = object
  205.         activeGravity[object] = { constraint = alignPos, attachment = objectAttachment }
  206.  
  207.         -- Legacy BodyVelocity-based gravity (does not support models)
  208.         -- The maths are untouched and are exactly identical to v4.0+
  209.     elseif gravityEngine == "bodyvelocity" or gravityEngine == "speed" or gravityEngine == "5" then
  210.         local legacy = legacyMasterFormula(object)
  211.         if legacy.force == 0 then
  212.             return
  213.         end
  214.         object.Velocity = object.Velocity + (legacy.direction * legacy.force)
  215.  
  216.         -- Whitehole mode
  217.         if gravity < 0 then
  218.             whiteHoleMode = true
  219.         end
  220.  
  221.         -- Legacy BodyForce-based gravity (supports models)
  222.     elseif gravityEngine == "bodyforce" or gravityEngine == "force" or gravityEngine == "6" then
  223.         local legacy = legacyMasterFormula(object)
  224.         local force = legacy.direction * legacy.force
  225.         local bodyForce = object:FindFirstChild("BlackHoleBodyForce", true)
  226.         if not bodyForce then
  227.             bodyForce = Instance.new("BodyForce")
  228.             bodyForce.Name = "BlackHoleBodyForce"
  229.             bodyForce.Force = force
  230.             bodyForce.Parent = object
  231.         else
  232.             bodyForce.Force = force
  233.         end
  234.  
  235.         -- Whitehole mode
  236.         if gravity < 0 then
  237.             whiteHoleMode = true
  238.         end
  239.     end
  240. end
  241.  
  242. -- Remove gravity constraints from an object
  243. local function RemoveGravity(object)
  244.     local data = activeGravity[object]
  245.     if data then
  246.         data.constraint:Destroy()
  247.         data.attachment:Destroy()
  248.         activeGravity[object] = nil
  249.     end
  250. end
  251.  
  252. -- Function to grow the black hole when it absorbs an object
  253. local function GrowBlackHole(object)
  254.     if growth and object:IsA("BasePart") then
  255.         local avgSize = (object.Size.X + object.Size.Y + object.Size.Z) / 3
  256.         local growthFactor = (1 / avgSize) * growthDamping
  257.         blackHole.Size = blackHole.Size + Vector3.new(growthFactor, growthFactor, growthFactor)
  258.         range = range + growthFactor
  259.         gravity = gravity + growthFactor
  260.         if gravity < 0 then gravity = gravity - growthFactor end
  261.         blackHole:FindFirstChild("BlackholeSound", true).RollOffMinDistance = range
  262.     end
  263. end
  264.  
  265. -- Function to absorb (and remove) an object
  266. local function AbsorbObject(object)
  267.     if growth then
  268.         GrowBlackHole(object)
  269.     end
  270.     RemoveGravity(object)
  271.     object:Destroy()
  272. end
  273.  
  274. local CollectionService = game:GetService("CollectionService")
  275.  
  276. -- Event listener for absorption on contact
  277. if absorption then
  278.     blackHole.Touched:Connect(function(hit)
  279.         if hit:IsA("BasePart") and hit ~= blackHole then
  280.             -- Merging logic for blackholes
  281.             if merging and CollectionService:HasTag(hit, "Blackholev5") then
  282.                 local otherBlackHole = hit
  283.                 local currentSize = blackHole.Size.X
  284.                 local otherSize = otherBlackHole.Size.X
  285.                 if currentSize < otherSize then
  286.                     local newSize = otherSize + currentSize
  287.                     otherBlackHole.Size = Vector3.new(newSize, newSize, newSize)
  288.                     if otherBlackHole:FindFirstChild("FX") and otherBlackHole:FindFirstChild("BlackholeSound", true) then
  289.                         otherBlackHole:FindFirstChild("BlackholeSound", true).RollOffMaxDistance = otherBlackHole:FindFirstChild("BlackholeSound", true).RollOffMaxDistance + currentSize
  290.                     end
  291.                     blackHole:Destroy()
  292.                 elseif currentSize > otherSize then
  293.                     local newSize = currentSize + otherSize
  294.                     blackHole.Size = Vector3.new(newSize, newSize, newSize)
  295.                     if blackHole:FindFirstChild("FX") and blackHole:FindFirstChild("BlackholeSound", true) then
  296.                         otherBlackHole:FindFirstChild("BlackholeSound", true).RollOffMaxDistance = otherBlackHole:FindFirstChild("BlackholeSound", true).RollOffMaxDistance + otherSize
  297.                     end
  298.                     otherBlackHole:Destroy()
  299.                 else
  300.                     local newSize = currentSize * 2
  301.                     blackHole.Size = Vector3.new(newSize, newSize, newSize)
  302.                     if blackHole:FindFirstChild("FX") and blackHole:FindFirstChild("BlackholeSound", true) then
  303.                         otherBlackHole:FindFirstChild("BlackholeSound", true).RollOffMaxDistance = otherBlackHole:FindFirstChild("BlackholeSound", true).RollOffMaxDistance * 2
  304.                     end
  305.                     otherBlackHole:Destroy()
  306.                 end
  307.                 return
  308.             end
  309.  
  310.             -- Normal absorption for non-blackhole objects
  311.             if not hit.Anchored then
  312.                 if absorption then
  313.                     if fading then
  314.                         hit.Anchored = anchoring
  315.                         hit.CanCollide = false
  316.                         local startTransparency = hit.Transparency
  317.                         local initialColor = hit.Color
  318.                         local elapsed = 0
  319.                         local heartbeat = game:GetService("RunService").Heartbeat
  320.                         local connection
  321.                         connection = heartbeat:Connect(function(delta)
  322.                             elapsed = elapsed + delta
  323.                             local progress = math.min(elapsed / fadeDuration, 1)
  324.                             hit.Transparency = startTransparency + (1 - startTransparency) * progress
  325.                             if colorShift then
  326.                                 hit.Color = initialColor:Lerp(color, progress)
  327.                             end
  328.                             if progress >= 1 then
  329.                                 connection:Disconnect()
  330.                                 AbsorbObject(hit)
  331.                             end
  332.                         end)
  333.                     else
  334.                         AbsorbObject(hit)
  335.                     end
  336.                 end
  337.             end
  338.         end
  339.     end)
  340. end
  341.  
  342. if microGravity then
  343.     workspace.Gravity = 0
  344. end
  345.  
  346. -- Blackhole sound setup
  347. if blackHoleSound then
  348.     blackHole:FindFirstChild("BlackholeSound", true).Playing = true
  349.     blackHole:FindFirstChild("BlackholeSound", true).RollOffMaxDistance = range
  350. end
  351.  
  352. -- Glint VFX
  353. if toggleEmitters then
  354.     blackHole:FindFirstChild("Glint", true).Enabled = true
  355. else
  356.     blackHole:FindFirstChild("Glint", true).Enabled = false
  357. end
  358.  
  359. -- Whitehole mode (if negative gravity/growth damping)
  360. if gravity < 0 and (gravityEngine == "linear1" or gravityEngine == "linear2" or gravityEngine == "1.1" or gravityEngine == "1.2" or gravityEngine == "line" or
  361.     gravityEngine == "2" or gravityEngine == "vector" or gravityEngine == "3" or gravityEngine == "bodyvelocity" or gravityEngine == "5" or gravityEngine == "bodyforce" or
  362.     gravityEngine == "6") then
  363.     local pureWhite = Color3.fromRGB(255, 255, 255)
  364.     blackHole:FindFirstChild("EventHorizon", true).FillColor = pureWhite
  365.     blackHole:FindFirstChild("EventHorizon", true).OutlineColor = pureWhite
  366.     blackHole:FindFirstChild("Glint", true).Color = ColorSequence.new(pureWhite)
  367.     blackHole:FindFirstChild("AccretionLight", true).Color = pureWhite
  368.     blackHole:FindFirstChild("Sparks", true).Enabled = toggleEmitters
  369.     blackHole:FindFirstAncestorWhichIsA("Model").Name = "Whitehole v5 Alpha"
  370.     blackHole.Color = pureWhite
  371.     blackHole.Name = "Whitehole_v5"
  372.     blackHole.CastShadow = false
  373.     absorption = false
  374.     cameraDistortion = false
  375.     distortSound = false
  376.     whiteHoleMode = true
  377. end
  378.  
  379. -- Lensing effect setup
  380. if lensing then
  381.     local lensingPart = blackHole.Parent:FindFirstChild("Lensing", true)
  382.     if lensingPart then
  383.         if gravity < 0 then
  384.             lensingPart.Size = Vector3.new(0, 0, 0)
  385.         else
  386.             lensingPart.Size = blackHole.Size * lensingFactor
  387.             lensingPart.Transparency = lensingStrength
  388.             if lensingPart.Transparency < 15 then
  389.                 lensingPart.Lensing.Adornee = lensingPart.LensingAttachment
  390.             else
  391.                 lensingPart.Lensing.Adornee = lensingPart
  392.             end
  393.         end
  394.     end
  395. else
  396.     local lensingPart = blackHole.Parent:FindFirstChild("Lensing", true)
  397.     if lensingPart then
  398.         lensingPart:Destroy()
  399.     end
  400. end
  401.  
  402. -- Cache initial values (run once)
  403. local initialBlackHoleSize = blackHole.Size.X
  404. local initialGlintSize, initialSparksSize
  405.  
  406. local fx = blackHole:FindFirstChild("FX")
  407. if fx then
  408.     local glint = fx:FindFirstChild("Glint")
  409.     if glint and glint.Size and #glint.Size.Keypoints > 0 then
  410.         initialGlintSize = glint.Size.Keypoints[1].Value
  411.     end
  412.     local sparks = fx:FindFirstChild("Sparks")
  413.     if sparks and sparks.Size and #sparks.Size.Keypoints > 0 then
  414.         initialSparksSize = sparks.Size.Keypoints[1].Value
  415.     end
  416. end
  417.  
  418. -- Main update loop
  419. game:GetService("RunService").Heartbeat:Connect(function()
  420.     -- Apply or remove gravity for parts in the workspace
  421.     for _, object in pairs(workspace:GetDescendants()) do
  422.         if object:IsA("BasePart") and object ~= blackHole and not object.Anchored then
  423.             local distance = (blackHole.Position - object.Position).Magnitude
  424.             local hasTag = CollectionService:HasTag(object, attractionTag)
  425.             if (gravitationMode == "selective" and hasTag and distance <= range) or (gravitationMode == "universal" and distance <= range and
  426.                 not CollectionService:HasTag(object, "BHcosmetic")) then
  427.                 ApplyGravity(object)
  428.             else
  429.                 RemoveGravity(object)
  430.             end
  431.         elseif activeGravity[object] then
  432.             RemoveGravity(object)
  433.         end
  434.     end
  435.  
  436.     -- Update active gravity constraints so they always point toward the black hole
  437.     for object, data in pairs(activeGravity) do
  438.         local distance = (blackHole.Position - object.Position).Magnitude  
  439.         if object:IsDescendantOf(workspace) and distance <= range then
  440.             local newDir = (blackHole.Position - object.Position).Unit
  441.             local effDist = clampDistance(distance)
  442.  
  443.             if data.constraint:IsA("VectorForce") then
  444.                 if realisticGravity then
  445.                     data.constraint.Force = newDir * masterFormula(object)
  446.                 else
  447.                     data.constraint.Force = newDir * gravity
  448.                 end
  449.             elseif data.constraint:IsA("LinearVelocity") then
  450.                 if data.constraint.VelocityConstraintMode == Enum.VelocityConstraintMode.Line then
  451.                     data.constraint.LineDirection = newDir
  452.                     if realisticGravity then
  453.                         data.constraint.LineVelocity = masterFormula(object)
  454.                     else
  455.                         data.constraint.LineVelocity = gravity
  456.                     end
  457.                 else
  458.                     local newVelocityMag = masterFormula(object) or 0
  459.                     data.constraint.VectorVelocity = newDir * newVelocityMag
  460.                 end
  461.             elseif data.constraint:IsA("LineForce") then
  462.                 if realisticGravity then
  463.                     data.constraint.Magnitude = masterFormula(object)
  464.                 else
  465.                     data.constraint.Magnitude = gravity
  466.                 end
  467.             elseif data.constraint:IsA("BodyVelocity") then
  468.                 local direction = blackHole.Position - object.Position
  469.                 local dist = clampDistance(direction.Magnitude)
  470.                 local forceMag = (gravity * blackHole.Size.X * object.Size.X) / (dist ^ 2)
  471.                 data.constraint.Velocity = object.Velocity + (direction.Unit * forceMag)
  472.             end
  473.         end
  474.     end
  475.  
  476.     -- Remove non-gravity constraints/joints from objects within the Roche radius
  477.     local rocheRadius = rocheFactor * blackHole.Size.X
  478.     if rocheRadius >= blackHole.Size.X then
  479.         for _, object in pairs(workspace:GetDescendants()) do
  480.             if object:IsA("BasePart") and object ~= blackHole then
  481.                 local dist = (blackHole.Position - object.Position).Magnitude
  482.                 if dist <= rocheRadius and not CollectionService:HasTag(object, "BHcosmetic") then
  483.                     for _, child in pairs(object:GetChildren()) do
  484.                         if child:IsA("Constraint") then
  485.                             if not (activeGravity[object] and activeGravity[object].constraint == child) then
  486.                                 local cname = child.ClassName
  487.                                 if cname ~= "LinearVelocity" and cname ~= "LineForce" and cname ~= "VectorForce" and cname ~= "AlignPosition" then
  488.                                     child:Destroy()
  489.                                 end
  490.                             end
  491.                         elseif child:IsA("JointInstance") then
  492.                             child:Destroy()
  493.                         end
  494.                     end
  495.                 end
  496.             end
  497.         end
  498.     end
  499.  
  500.     -- Camera distortion effect
  501.     if cameraDistortion and camera then
  502.         local camPos = camera.CFrame.Position
  503.         local distance = (blackHole.Position - camPos).Magnitude
  504.         local newFOV
  505.         if distance >= range then
  506.             newFOV = defaultFOV
  507.         elseif distance <= range * (distortThreshold / 100) then
  508.             newFOV = 120
  509.         else
  510.             local t = (range - distance) / (range - distortThreshold)
  511.             newFOV = defaultFOV + t * (120 - defaultFOV)
  512.         end
  513.         camera.FieldOfView = newFOV
  514.     end
  515.  
  516.     -- Sound pitch distortion effect for nearby blackholes
  517.     if distortSound then
  518.         local closestDist = math.huge
  519.         for _, bh in pairs(CollectionService:GetTagged("Blackholev5")) do
  520.             if bh ~= blackHole and bh:IsDescendantOf(workspace) then
  521.                 local d = (blackHole.Position - bh.Position).Magnitude
  522.                 if d < closestDist then
  523.                     closestDist = d
  524.                 end
  525.             end
  526.         end
  527.         local newPitch = 1
  528.         if closestDist < math.huge then
  529.             if closestDist <= range / 2 then
  530.                 newPitch = 1 - (closestDist / range)
  531.             else
  532.                 newPitch = 1
  533.             end
  534.         end
  535.         local pitchEffect = blackHole:FindFirstChild("BlackholeSound", true).PitchDistortion
  536.         if pitchEffect then
  537.             pitchEffect.Octave = newPitch
  538.         end
  539.     end
  540.  
  541.     -- Update Glint and Sparks emitters, range, sound, and lensing based on blackHole size changes
  542.     local currentSize = blackHole.Size.X
  543.     if currentSize > previousSize then  -- only update when growing
  544.         local scaleFactor = currentSize / initialBlackHoleSize
  545.  
  546.         if fx then
  547.             -- Update Glint emitter size based on the original size
  548.             local glint = fx:FindFirstChild("Glint")
  549.             if glint then
  550.                 glint.Size = NumberSequence.new(initialGlintSize * scaleFactor)
  551.             end
  552.             -- Update Sparks emitter size based on the original size
  553.             local sparks = fx:FindFirstChild("Sparks")
  554.             if sparks then
  555.                 sparks.Size = NumberSequence.new(initialSparksSize * scaleFactor)
  556.             end
  557.             -- Lensing effect update
  558.             if lensing then
  559.                 local lensingPart = blackHole.Parent:FindFirstChild("Lensing", true)
  560.                 if lensingPart then
  561.                     lensingPart.Size = blackHole.Size * lensingFactor
  562.                 end
  563.             end
  564.         end
  565.         -- You can update other properties (range, sound, etc.) as before
  566.         range = range * (currentSize / previousSize)
  567.         blackHole:FindFirstChild("BlackholeSound", true).RollOffMaxDistance = range
  568.  
  569.         previousSize = currentSize
  570.     end
  571. end)
  572.  
  573. -- Logging and error handling. Its all on me, dont worry
  574. if logging then
  575.     local gE = gravityEngine
  576.     local gM = gravitationMode
  577.     local aT = attractionTag
  578.     print("{-- | Blackhole v5 Alpha Logger | --}")
  579.     if gE == "linear1" or gE == "1.1" or gE == "linear2" or gE == "1.2" then
  580.         print("{BHv5: Running LinearVelocity gravity}")
  581.     elseif gE == "line" or gE == "2" then
  582.         print("{BHv5: Running LineForce gravity}")
  583.     elseif gE == "vector" or gE == "3" then
  584.         print("{BHv5: Running VectorForce gravity}")
  585.     elseif gE == "align" or gE == "4" then
  586.         print("{BHv5: Running AlignPosition gravity}")
  587.     elseif gE == "bodyvelocity" or gE == "speed" or gE == "5" then
  588.         print("{BHv5: Running LEGACY BodyVelocity gravity}")
  589.         print("{   BodyVelocity is unstable but accurate. It does NOT support models!}")
  590.         print("{   Consider this when running it}")
  591.     elseif gE == "bodyforce" or gE == "force" or gE == "6" then
  592.         print("{BHv5: Running LEGACY BodyForce gravity}")
  593.         print("{   BodyVelocity is stable but inaccurate. This supports models}")
  594.         print("{   Consider this when running it}")
  595.     else
  596.         warn("{BHv5: Unrecognised gravity engine: '" .. tostring(gE) .. "'")
  597.         warn("{   Switching to default gravity}")
  598.         gravityEngine = "1.1"
  599.     end
  600.     if gM == "universal" or gM == "selective" then
  601.         print("{BHv5: Set to " .. tostring(gM:upper()) .. " gravitation}")
  602.     else
  603.         warn("{BHv5: Unrecognised mode: '" .. tostring(gM) .. "'")
  604.         warn("{   Setting to default gravitation mode}")
  605.         gravitationMode = "universal"
  606.     end
  607.     print("{BHv5: Current attraction tag is '" .. tostring(aT) .. "'}")
  608.     if logSettings then
  609.         print("{v5 Settings}")
  610.         print("{G  Current gravity is " .. tostring(gravity) .. "}")
  611.         if whiteHoleMode == true then warn("{G  Blackhole has negative gravity! (whitehole mode)}") blackHole.Parent:FindFirstChild("Lensing", true):Destroy() end
  612.         if range < 0 then warn("{G  Range cannot be less than 0! Please enter a positive integer}") else print("{G  Initial range is " .. tostring(range) .. "}") end
  613.         if gE == "align" or gE == "4" then
  614.             print("{G  Aligning speed is " .. tostring(alignSpeed) .. "}")
  615.         end
  616.         if realisticGravity then print("{G  Realistic gravity is Enabled}") else
  617.             print("{G  Realistic gravity is Disabled}")
  618.         end
  619.         if realGravDamping < 0 then warn("{G  Realistic Gravity Damping cannot be less than zero! (set to 1)}") end
  620.         if microGravity then print("{G  Workspace gravity is Disabled}") else
  621.             print("{G  Workspace gravity is Enabled}")
  622.         end
  623.         if absorption then print("{A  Absorption is Enabled}") else
  624.             print("{A  Absorption is Disabled}")
  625.         end
  626.         if growth then print("{A  The blackhole can grow with a damping of " .. tostring(growthDamping) .. "}") else
  627.             print("{A  The Blackhole cannot grow}")
  628.         end
  629.         local sT = " seconds}"
  630.         if fadeDuration == 1 then sT = " second}" else sT = " seconds}" end
  631.         if fading then
  632.             print("{A  Absorbed objects can fade out for " .. tostring(fadeDuration) .. sT)
  633.             if colorShift then print("{A  Objects shift in color when fading}") else
  634.                 print("{A  Objects do not shift in color when fading}")
  635.             end
  636.         else
  637.             print("{A  Absorbed objects do not fade out, therefore it cannot shift in color}")
  638.         end
  639.         if anchoring then print("{A  Objects freeze when fading}") else
  640.             print("{A  Objects do not freeze when fading}")
  641.         end
  642.         print("{A  Fragmentation occurs at " .. tostring(rocheFactor) .. "x the blackhole's radius}")
  643.         if merging then print("{A  Blackholes can merge}") else
  644.             print("{A  Blackholes cannot merge}")
  645.         end
  646.         if lensing then print("{S  Light is bent within " .. tostring(lensingFactor) .. "x the blackhole's radius with an intensity of " .. tostring(lensingStrength .. "}")) else
  647.             print("{S  Light is not bent around the blackhole}")
  648.         end
  649.         if cameraDistortion then print("{S  FOV is alterable within range until " .. tostring(distortThreshold) .. "% of it (in editor/server mode)}") else
  650.             print("{S  FOV is not altered within range}")
  651.         end
  652.         if blackHoleSound then print("{S  The blackhole has sound}") else
  653.             print("{S  The blackhole does not have sound}")
  654.         end
  655.         if distortSound then print("{S  The blackhole sound is alterable within range [BETA]}") else
  656.             print("{S  The blackhole sound is not alterable}")
  657.         end
  658.         if toggleEmitters then print("{S  Visual effects are Enabled}") else print("{S  Visual effects are Disabled}") end
  659.         print("{S  Glint size should be proportional as long as the blackhole is a model}")
  660.     else
  661.         print("{BHv5: Settings report is disabled}")
  662.     end
  663.     print("{Programming by zaragosa126}")
  664. end
Tags: Rescripted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement