Advertisement
This is comment for paste
Blackhole v5.0 Prototype
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [ 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement