Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [ Blackhole 5.0 Source Code Prototype ] --
- -- Integrated smoother graviational forces for stable simulations.
- -- Archived versions - visit my pastebin: https://pastebin.com/u/1m1m0
- local hole = script.Parent -- Quick Documentation, more at 「Documentation」
- local gravitationalConstant = 1000 -- Adjust this value to control the strength of the attraction [1000 is default for a black hole]
- local updateInterval = 0 -- Time in seconds between updates while computing (Higher = +Accuracy -Performance, Lower = -Accuracy +Performance)
- 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]
- local rangeFactor = 500 -- Maximum range for objects to be effected [500 studs is default]
- local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes. (Appearing to fade out of reality)
- local dematerializeDuration = 0.01 -- How long (seconds) the fading will last (In seconds) on each transparency increment
- local sizeProportion = 50 -- Smaller = faster growth for each absorption
- local rangeProportion = 125 -- Bigger = faster range growth
- local partColor = BrickColor.new(0) -- Color it changes into before getting deleted. (White is default)
- local partMaterialTransform = Enum.Material.Neon -- Material it changes into before getting deleted. (Neon is default)
- local absorption = true -- Absorb objects that touch the blackhole
- local growth = true -- Allow the blackhole to grow by absorption
- local killPlayers = true -- Kill players that touch the blackhole
- local collision = false -- Make objects pass through eachother while being absorbed
- local fixedPosition = true -- Anchor objects while being absorbed (Better FPS)
- local toggleMicroGravity = true -- This script works best in zero gravity environments! (Optional)
- -- GRAVITATIONAL FORCES --
- local lastUpdateTime = 0
- local function ApplyGravity(object)
- -- Delay to pause calculations for better FPS
- local currentTime = tick()
- if currentTime - lastUpdateTime < updateInterval then return end
- lastUpdateTime = currentTime
- -- Main bulk of gravitational forces
- local direction = hole.Position - object.Position
- local distance = direction.Magnitude
- -- ---Dont touch, this formula has been tweaked for exact range of effectiveness!--- --
- local distanceSquared = (distance/((rangeFactor/100) + ((rangeFactor/100)*(1/64)))) ^ 2
- -- --------------------------------------------------------------------------------- --
- local magnitude = gravitationalConstant / distanceSquared
- local force = direction.Unit * magnitude * object:GetMass()
- local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
- if not bodyForce then
- bodyForce = Instance.new("BodyForce")
- bodyForce.Name = "BlackHoleBodyForce"
- bodyForce.Force = Vector3.new(0, 0, 0)
- bodyForce.Parent = object
- end
- -- Apply damping to the force to prevent instability
- bodyForce.Force = (bodyForce.Force + force) * damping
- end
- -- MAIN GRAVITATIONAL FORCE COMPUTER (Applies gravity to anything) --
- local function CheckAndApplyGravity(obj)
- -- Check if the object is a descendant of a BasePart (including all physical objects)
- if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then
- return
- end
- -- Exclude the black hole itself and players from gravitational pull
- if obj == hole or obj.Parent:IsA("Player") then -- Remove obj.Parent:IsA("Player") if you like
- return
- end
- -- Exclude anchored objects to maximize performance
- if obj.Anchored then
- return
- end
- ApplyGravity(obj)
- end
- game:GetService("RunService").Heartbeat:Connect(function()
- for _, object in pairs(game.Workspace:GetDescendants()) do
- CheckAndApplyGravity(object)
- end
- end)
- -- DAMAGE/KILLER (Kills players when they touch it) --
- function onTouch(part)
- local humanoid = part.Parent:FindFirstChild("Humanoid")
- if humanoid then
- humanoid.Health = 0
- end
- end
- if killPlayers then
- hole.Touched:Connect(onTouch)
- end
- -- DEMATERIALIZER (Deletes ANY object that touches it) --
- function onTouched(part)
- if part.Anchored then -- Prevent anchored objects from being absorbed
- return
- end
- -- Calculate average mean size of objects
- local function CalculateAverageSize(part)
- local size = part.Size
- local averageSize = (size.X + size.Y + size.Z) / 3
- return averageSize
- end
- local objectAverageSize = CalculateAverageSize(part)
- local blackHoleSize = hole.Size.X
- -- Calculate the new size increment based on the object's average size
- local sizeIncrement = (objectAverageSize / (blackHoleSize * sizeProportion))
- part.BrickColor = partColor
- part.Material = partMaterialTransform
- part.CanCollide = collision
- part.Anchored = fixedPosition
- for _, transparency in ipairs(transparencySteps) do
- part.Transparency = transparency
- wait(dematerializeDuration)
- end
- part:Destroy() -- Delete part after completing transparencySteps
- if growth then
- -- Adjust the black hole's size based on the new size increment
- hole.Size = hole.Size + Vector3.new(sizeIncrement, sizeIncrement, sizeIncrement)
- rangeFactor = rangeFactor + sizeIncrement * rangeProportion
- end
- end
- if absorption then
- local connection = hole.Touched:Connect(onTouched)
- end
- if toggleMicroGravity then
- game.Workspace.Gravity = 0
- end
Advertisement
Comments
-
- -- [ Blackhole 5.0 Source Code Prototype ] --
- -- DEV VERSION - Experimental use only
- local hole = script.Parent
- local gravitationalConstant = 1000
- local updateInterval = 0
- local damping = 0.7
- local rangeFactor = 250
- local transparencySteps = {0.25, 0.5, 0.75}
- local dematerializeDuration = 0.01
- local partColor = BrickColor.new(0)
- local partMaterialTransform = Enum.Material.Neon
- local collision = true
- local fixedPosition = false
- local lastUpdateTime = 0
- local function ApplyGravity(object)
- local currentTime = tick()
- if currentTime - lastUpdateTime < updateInterval then return end
- lastUpdateTime = currentTime
- local direction = hole.Position - object.Position
- local distance = direction.Magnitude
- local distanceSquared = ((distance*6400) / (rangeFactor*65)) ^ 2
- local magnitude = gravitationalConstant / distanceSquared
- local force = direction.Unit * magnitude * object:GetMass()
- local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
- if not bodyForce then
- bodyForce = Instance.new("BodyForce")
- bodyForce.Name = "BlackHoleBodyForce"
- bodyForce.Force = Vector3.new(0, 0, 0)
- bodyForce.Parent = object
- end
- bodyForce.Force = (bodyForce.Force + force) * damping
- end
- local function CheckAndApplyGravity(obj)
- if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then
- return
- end
- if obj == hole or obj.Parent:IsA("Player") then
- return
- end
- if obj.Anchored then
- return
- end
- ApplyGravity(obj)
- end
- game:GetService("RunService").Heartbeat:Connect(function()
- for _, object in pairs(game.Workspace:GetDescendants()) do
- CheckAndApplyGravity(object)
- end
- end)
- function onTouched(part)
- part.BrickColor = partColor
- part.Material = partMaterialTransform
- part.CanCollide = collision
- part.Anchored = fixedPosition
- for _, transparency in ipairs(transparencySteps) do
- part.Transparency = transparency
- wait(dematerializeDuration)
- end
- part:Destroy()
- end
- --[
- local connection = hole.Touched:Connect(onTouched)
- --]]
-
- -- [ Blackhole 5.1 Source Code Prototype ] --
- -- Integrated smoother gravitational forces for stable simulations.
- -- For archived versions, visit my pastebin: https://pastebin.com/u/1m1m0
- game.Workspace.Gravity = 0 -- This script works best in zero gravity environments! (Optional)
- local hole = script.Parent
- local gravitationalConstant = 1000 -- Adjust this value to control the strength of the attraction [1000 is default for a black hole]
- local updateInterval = 0 -- Time in seconds between updates while computing (Higher = +Accuracy -Performance, Lower = -Accuracy +Performance)
- 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]
- local rangeFactor = 500 -- Maximum range for objects to be effected [500 studs is default]
- local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes. (Appearing to fade out of reality)
- local dematerializeDuration = 0.01 -- How long (seconds) the fading will last (In seconds) on each transparency increment
- local sizeProportion = 50 -- Smaller = faster growth for each absorption
- local rangeProportion = 125 -- Bigger = faster range growth
- local partColor = BrickColor.new(0) -- Color it changes into before getting deleted. (White is default)
- local partMaterialTransform = Enum.Material.Neon -- Material it changes into before getting deleted. (Neon is default)
- local absorption = true -- Absorb objects that touch the blackhole
- local growth = true -- Allow the blackhole to grow by absorption
- local killPlayers = true -- Kill players that touch the blackhole
- local collision = false -- Make objects pass through eachother while being absorbed
- local fixedPosition = false -- Anchor objects while being absorbed (Better FPS)
- -- gravitational constants of half or a third of 1000 is perfect for gentle simulations.
- -- GRAVITATIONAL FORCES --
- local lastUpdateTime = 0
- local function ApplyGravity(object)
- -- Delay to pause calculations for better FPS
- local currentTime = tick()
- if currentTime - lastUpdateTime < updateInterval then return end
- lastUpdateTime = currentTime
- -- Main bulk of gravitational forces
- local direction = hole.Position - object.Position
- local distance = direction.Magnitude
- -- ---Dont touch, this formula has been tweaked for exact range of effectiveness!--- --
- local distanceSquared = (distance/((rangeFactor/100) + ((rangeFactor/100)*(1/64)))) ^ 2
- -- --------------------------------------------------------------------------------- --
- local magnitude = gravitationalConstant / distanceSquared
- local force = direction.Unit * magnitude * object:GetMass()
- local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
- if not bodyForce then
- bodyForce = Instance.new("BodyForce")
- bodyForce.Name = "BlackHoleBodyForce"
- bodyForce.Force = Vector3.new(0, 0, 0)
- bodyForce.Parent = object
- end
- -- Apply damping to the force to prevent instability
- bodyForce.Force = (bodyForce.Force + force) * damping
- end
- -- MAIN GRAVITATIONAL FORCE COMPUTER (Applies gravity to anything) --
- local function CheckAndApplyGravity(obj)
- -- Check if the object is a descendant of a BasePart (including all physical objects)
- if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then
- return
- end
- -- Exclude the black hole itself and players from gravitational pull
- if obj == hole or obj.Parent:IsA("Player") then -- Remove obj.Parent:IsA("Player") if you like
- return
- end
- -- Exclude anchored objects to maximize performance
- if obj.Anchored then
- return
- end
- ApplyGravity(obj)
- end
- game:GetService("RunService").Heartbeat:Connect(function()
- for _, object in pairs(game.Workspace:GetDescendants()) do
- CheckAndApplyGravity(object)
- end
- end)
- -- DAMAGE/KILLER (Kills players when they touch it) --
- function onTouch(part)
- local humanoid = part.Parent:FindFirstChild("Humanoid")
- if humanoid then
- humanoid.Health = 0
- end
- end
- if killPlayers then
- hole.Touched:Connect(onTouch)
- end
- -- DEMATERIALIZER (Deletes ANY object that touches it) --
- function onTouched(part)
- if part.Anchored then -- Prevent anchored objects from being absorbed
- return
- end
- -- Calculate average mean size of objects
- local function CalculateAverageSize(part)
- local size = part.Size
- local averageSize = (size.X + size.Y + size.Z) / 3
- return averageSize
- end
- local objectAverageSize = CalculateAverageSize(part)
- local blackHoleSize = hole.Size.X
- -- Calculate the new size increment based on the object's average size
- local sizeIncrement = (objectAverageSize / (blackHoleSize * sizeProportion))
- part.BrickColor = partColor
- part.Material = partMaterialTransform
- part.CanCollide = collision
- part.Anchored = fixedPosition
- for _, transparency in ipairs(transparencySteps) do
- part.Transparency = transparency
- wait(dematerializeDuration)
- end
- part:Destroy() -- Delete part after completing transparencySteps
- if growth then
- -- Adjust the black hole's size based on the new size increment
- hole.Size = hole.Size + Vector3.new(sizeIncrement, sizeIncrement, sizeIncrement)
- rangeFactor = rangeFactor + sizeIncrement * rangeProportion
- end
- end
- if absorption then
- local connection = hole.Touched:Connect(onTouched)
- end
-
- -- [ Blackhole 5.0 Source Code Prototype ] --
- -- Integrated smoother gravitational forces for stable simulations.
- -- For archived versions, visit my pastebin: https://pastebin.com/u/1m1m0
- -- No, i did not get a bachelor of physics just for this
- game.Workspace.Gravity = 0 -- This script works best in zero gravity environments! (Optional)
- local hole = script.Parent
- local gravitationalConstant = 1000 -- Adjust this value to control the strength of the attraction [1000 is default for a black hole]
- local updateInterval = 0 -- Time in seconds between updates while computing (Higher = +Accuracy -Performance, Lower = -Accuracy +Performance)
- 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]
- local rangeFactor = 500 -- Maximum range for objects to be effected [500 studs is default]
- local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes. (Appearing to fade out of reality)
- local dematerializeDuration = 0.01 -- How long (seconds) the fading will last (In seconds) on each transparency increment
- local sizeProportion = 35 -- Smaller = faster growth for each absorption
- local rangeProportion = 125 -- Bigger = faster range growth
- local partColor = BrickColor.new(0) -- Color it changes into before getting deleted. (White is default)
- local partMaterialTransform = Enum.Material.Neon -- Material it changes into before getting deleted. (Neon is default)
- local absorption = false -- Absorb objects that touch the blackhole
- local growth = true -- Allow the blackhole to grow by absorption
- local killPlayers = true -- Kill players that touch the blackhole
- local collision = false -- Make objects pass through eachother while being absorbed
- local fixedPosition = false -- Anchor objects while being absorbed (Better FPS)
- local forceStabilizer = false -- Toggle to decelerate objects when entering event horizon from infinity
- -- GRAVITATIONAL FORCES --
- local lastUpdateTime = 0
- --[
- local function ApplyGravity(object)
- local direction = hole.Position - object.Position
- local distance = direction.Magnitude
- local blackHoleRadius = hole.Size.X / 2
- -- Prevents objects from accelerating too fast
- if distance < blackHoleRadius and forceStabilizer then
- direction = -direction
- elseif distance < blackHoleRadius then
- return
- end
- -- Set up main physics calculations
- local distanceSquared = (distance/((rangeFactor/100) + ((rangeFactor/100)*(1/64)))) ^ 2 -- Dont touch lol
- local magnitude = gravitationalConstant / distanceSquared
- local force = direction.Unit * magnitude * object:GetMass()
- local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
- if not bodyForce then
- bodyForce = Instance.new("BodyForce")
- bodyForce.Name = "BlackHoleBodyForce"
- bodyForce.Force = Vector3.new(0, 0, 0)
- bodyForce.Parent = object
- end
- -- Apply the force, reversed if within the black hole's volume
- bodyForce.Force = (bodyForce.Force + force) * damping
- end
- -- MAIN GRAVITATIONAL FORCE COMPUTER (Applies gravity to anything) --
- local function CheckAndApplyGravity(obj)
- -- Check if the object is a descendant of a BasePart (including all physical objects)
- if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then
- return
- end
- -- Exclude the black hole itself and players from gravitational pull
- if obj == hole or obj.Parent:IsA("Player") then -- Remove obj.Parent:IsA("Player") if you like
- return
- end
- -- Exclude anchored objects to maximize performance
- if obj.Anchored then
- return
- end
- ApplyGravity(obj)
- end
- game:GetService("RunService").Heartbeat:Connect(function()
- for _, object in pairs(game.Workspace:GetDescendants()) do
- CheckAndApplyGravity(object)
- end
- end)
- -- DAMAGE/KILLER (Kills players when they touch it) --
- function onTouch(part)
- local humanoid = part.Parent:FindFirstChild("Humanoid")
- if humanoid then
- humanoid.Health = 0
- end
- end
- if killPlayers then
- hole.Touched:Connect(onTouch)
- end
- -- DEMATERIALIZER (Deletes ANY object that touches it) --
- function onTouched(part)
- if part.Anchored then -- Prevent anchored objects from being absorbed
- return
- end
- local initialBlackHoleSize = hole.Size.X
- local initialRangeFactor = rangeFactor
- -- Calculate average mean size of objects
- local function CalculateAverageSize(part)
- local size = part.Size
- local averageSize = (size.X + size.Y + size.Z) / 3
- return averageSize
- end
- local objectAverageSize = CalculateAverageSize(part)
- local blackHoleSize = hole.Size.X
- -- Calculate the new size increment based on the object's average size
- local sizeIncrement = (objectAverageSize / (blackHoleSize * sizeProportion))
- part.BrickColor = partColor
- part.Material = partMaterialTransform
- part.CanCollide = collision
- part.Anchored = fixedPosition
- for _, transparency in ipairs(transparencySteps) do
- part.Transparency = transparency
- wait(dematerializeDuration)
- end
- part:Destroy() -- Delete part after completing transparencySteps
- if growth then
- -- Adjust blackhole size
- hole.Size = hole.Size + Vector3.new(sizeIncrement, sizeIncrement, sizeIncrement)
- -- Growth ratio
- local growthRatio = hole.Size.X / initialBlackHoleSize
- -- Apply growth ratio
- rangeFactor = initialRangeFactor * growthRatio
- end
- end
- if absorption then
- local connection = hole.Touched:Connect(onTouched)
- end
-
- --[[
- -- [Blackhole v5 Prototype Documentation] Nov. 30, 2024 --
- --------
- PHYSICAL
- IMPORTANT: Note that the blackhole is a MeshPart, resize the blackhole by holding 「alt」 to preserve proportions!
- 「toggleMicroGravity」 (quickly disable gravity) can be turned off or on if you dont want to go into the game settings manually.
- Change blackhole properties like 「EventHorizon」 (pitch black effect), color, transparency, mass, custom physical properties and more to your liking.
- --------
- -------
- GRAVITY
- Blackhole v5 Prototype runs on BodyForce-based gravity. Blackhole v4.0+ runs on Velocity-based gravity, v4 Betas are hybrid-based (force or velocity).
- 「gravitationalConstant」 is the base strength of the blackhole's overall gravity, which are manipulated by 「damping」 (suppresses violent simulation between 0 & 1),
- and 「rangeFactor」 (area in studs where objects are pulled in, anything outside that is not affected. gravity is amplified for bigger values).
- -------
- ------------------------
- ABSORPTION & PERFORMANCE
- Objects are absorbed if 「absorption」 is enabled, which will follow 「transparencySteps」 (fading effect between 1 & 0 invisibilities)
- in a span of 「dematerializeDuration」 (time to progress each transparency step) while 「partMaterialTransform」 (material absorbed objects turn into) and
- 「partColor」 (color absorbed objects turn into) lead the object into deletion, causing 「growth」 to make the blackhole bigger and stronger with
- 「sizeProportion」 (how fast the blackhole grows, bigger means slower growth) and 「rangeProportion」 (how fast rangeFactor grows, bigger means faster growth).
- 「killPlayers」 (kills absorbed players) can be turned on or off when simulating with a player.
- 「fixedPosition」 (anchor absorbed objects) can help with performance, along with 「collision」 (make objects pass through eachother while being absorbed), and
- 「updateInterval」 (value in seconds to update gravitational forces. lower values are accurate but slower, higher values are inaccurate but faster).
- If 「absorption」 is disabled, everything above within ABSORPTION is excluded EXCEPT 「killPlayers」.
- ------------------------
- --------
- ADVANCED
- If you know how to code, you can edit the script to your liking.
- Tips:
- In 「CheckAndApplyGravity(obj)」, you can change 「if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then return end」 to exclude specific objects.
- Changing 「if obj == hole or obj.Parent:IsA("Player") then return end」 will cause glitches. however, you may change 「obj.Parent:IsA("Player")」 without issues.
- Tinkering with 「ApplyGravity(object)」 and 「onTouched(part)」 can throw simulation accuracy off, modify cautiously.
- --------
- ]]
Add Comment
Please, Sign In to add comment
Advertisement