Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [ Blackhole 4.0 Source Code Basics ] --
- -- Does not contain special functions as v4.3+, but does contain some aspects of v5.0+
- -- For archived versions of v4.3+, visit my pastebin: https://pastebin.com/u/1m1m0
- local hole = script.Parent
- local gravitationalConstant = 1000 -- Adjust this value to control the strength of the attraction [1000 is default for a black hole]
- -- gravitational constants of half or a third of 1000 is perfect for gentle simulations.
- local velocityBasedGravity = true -- Toggle for velocity-base gravity (good for large scale simulations)
- local forceBasedGravity = false -- Toggle for bodyforce-base gravity (good for small scale simulations, LIMITED RANGE)
- local absorption = true -- Toggle to absorb objects or not
- -- How the blackhole will pull objects (Uses VELOCITY, unlimited range, unstable simulations)
- if velocityBasedGravity then
- function ApplyGravity(object)
- local direction = hole.Position - object.Position
- local distance = direction.Magnitude
- local forceMagnitude = (gravitationalConstant * hole.Size.X * object.Size.X) / (distance * distance)
- local force = direction.Unit * forceMagnitude
- object.Velocity = object.Velocity + force
- end
- elseif forceBasedGravity then
- -- Alternative gravitational pull. (Uses BODYFORCE, limited range, stable simulations)
- local function ApplyGravity(object)
- local direction = hole.Position - object.Position
- local force = direction.Unit * gravitationalConstant
- local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
- if not bodyForce then
- bodyForce = Instance.new("BodyForce")
- bodyForce.Name = "BlackHoleBodyForce"
- bodyForce.Force = force
- bodyForce.Parent = object
- else
- bodyForce.Force = force
- end
- end
- end
- local function CheckAndApplyGravity(obj)
- if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then -- This should include everything
- return
- end
- -- [Objects only]
- if obj == hole or obj == obj:IsA("Player") then
- return -- Excludes the players and black hole itself from gravitational pull, feel free to add more.
- end
- -- [Unanchored objects only]
- if obj.Anchored then
- return -- Prevents black hole from applying gravity to the anchored objects. (Saves resources and compuation power)
- 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
- -- DEMATERIALIZER (Deletes ANY object that touches it) --
- hole.Touched:Connect(onTouch)
- if absorption then
- function onTouched(part)
- if part.Anchored then -- Exclude anchored objects
- return
- end
- part.BrickColor = BrickColor.new(0) -- Color it changes into before getting deleted. (White is default)
- part.Material = Enum.Material.Neon -- Material it changes into before getting deleted. (Neon is default)
- --[[ Additional absorption styles:
- part.Anchored = true
- part.CanCollide = false
- --]]
- local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes. (Appearing to fade out of reality)
- for _, transparency in ipairs(transparencySteps) do
- part.Transparency = transparency
- wait(0.01) -- How long (seconds) the fading will last (In seconds) on each transparency increment.
- end
- part:Destroy() -- Delete part after completing trancparencySteps.
- end
- local connection = hole.Touched:Connect(onTouched)
- end
- -- (Do not credit me for this masterpiece of a script, all credit goes to ChatGPT who made this masterpiece into reality!) --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement